如果在给定矩阵B
的大小时移除uint8
,则会得到一个被红色平面覆盖的输出。我还在imshow(B, [])
中添加了[]
,以解决全暗输出的问题,但这并没有帮助。
function myThirdAssignment(I,WindowSize,K0,K1,K2)
%if size(I,3)==1
%[rows, columns, numberOfColorChannels] = size(I);
%elseif size(I,3)==3
x= im2double(imread(I));
%gray1=rgb2gray(x);
%[r, c, numberOfColorChannels] = size(gray1);
%end
if nargin==1 % If number of arguments of the function are equal to 1 then use
% the following default values for K0,K1,K2, & Window size.
K0= 0.5;
K1= 1;
K2= 0.5;
WindowSize=3;
end
figure(1); imshow(x); title('ORIGINAL IMAGE');
imwrite(x,'OriginalImage.bmp.bmp'); %writing data of original image in to current directory.
% GIVING B THE SAME ROWS AND COLUMS AS THE ORIGINAL IMAGE
[rows, columns, numberOfColorChannels] = size(x);
B = zeros(rows, columns, numberOfColorChannels, 'uint8');
% CALCULATING CEIL & FLOOR VALUES TO MAKE PROGRAM MORE GENERAL
p= ceil((WindowSize / 2)); %3/2= 1.5=2
s= floor((WindowSize / 2)); %3/2=1.5=1
B(i,j)= 2*x(i,j);
else
B(i,j)= x(i,j);
end
%--------------------------------------------
end
end
%RGB = cat(3, B, B, B);
figure(2);imshow(B, []); title('IMAGE AFTER LOCAL HISTOGRAM EQUALIZATION');
imwrite(B,'enhancedImage.jpeg.jpeg'); %writing data of enhanced image in to current directory
end
我用这个图像作为输入。
这里有两个问题:a(您已经解决的uint8问题,它将双值转换为uint8,将所有值四舍五入为0,导致暗图像,和b(产生的红色图像,这是因为你只对输入图像x的红色通道执行局部直方图均衡,而输出图像中的绿色和蓝色通道为零。
将您的代码更改为:
if avg <= K0*(meanIntensity) && (K1*(stdG) <= std) && (std <= K2*(stdG))
% only enhance an area of defined window size when its mean/average is
% lesser than or equal to the mean of the image by some constant
% K0 AND its standard deviation is lesser than the value of the
% standard deviation by a constant K2 and greater than the
% global standard deviation by a constant K1.
B(i,j,1)= 2*x(i,j,1);
B(i,j,2)= 2*x(i,j,2);
B(i,j,3)= 2*x(i,j,3);
else
B(i,j,1)= x(i,j,1);
B(i,j,2)= x(i,j,2);
B(i,j,3)= x(i,j,3);
end
x
是双(im2double
(,意味着其值介于0和1之间。
您将它存储在一个从0-255到B
的无符号整数上。作为一个无符号整数,它将裁剪所有小数点,并四舍五入到最接近的int,即0。所以B(i,j)= x(i,j)
总是零。
你的意思可能是B(i,j)= x(i,j)*255
?
或者更好的是,只要总是对doubles进行操作,然后在保存之前转换int(如果需要的话(。