i have this code of " Power law transformation " on an image ?? why is the error occuring ??
조회 수: 6(최근 30일)
a = imread('pout.tif') imshow(a); title('Original Image') gray = rgb2gray(a); I = im2double(gray) [row col] = size(I); c=input('Enter value of Constant: '); g=[0.2 0.5 0.8 1 1.2 1.6 2];
for i=1:size(g) for x=1:row for y=1:col pt=I(x,y); d=power(pt,g(i)); b=c*d; end end imshow(uint8(b)); title('Power Law Transformed Image'); end
DGM 2022년 11월 27일
There are a few things wrong here, but this question demonstrates one thing very clearly. If you can't be bothered to post readable code, then don't expect anyone to bother answering within the same decade.
To resolve the other issues, try this.
% any single-frame image
inpict = imread('pout.tif');
% change to unit-scale float
inpict = im2double(inpict);
% don't harass the user repeatedly for trivial inputs
% set them as parameters once
expos = 1; % simple multiplicative "exposure" adjustment
gamma = [0.2 0.5 0.8 1 1.2 1.6 2]; % gamma constants
% display a series of adjusted images
for i = 1:numel(g) % numel(), not size()
outpict = expos*power(inpict,g(i)); % don't need a loop
title('Power Law Transformed Image');
pause(0.5) % pause so that the output can be seen
The difference between simple multiplicative "exposure" and "contrast" adjustments is simply where the pivot point is. While I left it in my answer, I question its appropriateness and the order of operations. For most uses, imadjust() should work fine for this, as it supports gamma and levels adjustment. There are also various third party tools that offer more traditional controls.