获取全暗输出图像
Getting all dark output image
如果我在给矩阵 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
我使用 this image 作为输入。
x
是double (im2double
),意思是它的值在0到1之间。
您将其存储在 0-255 的无符号整数上,B
。作为无符号整数,它将裁剪所有小数位并舍入到最接近的整数,即 0。因此 B(i,j)= x(i,j)
始终为零。
您的意思可能是 B(i,j)= x(i,j)*255
?
或者更好的是,始终对双精度数进行运算,然后在保存之前转换 int,如果需要的话。
这里有两个问题: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
如果我在给矩阵 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
我使用 this image 作为输入。
x
是double (im2double
),意思是它的值在0到1之间。
您将其存储在 0-255 的无符号整数上,B
。作为无符号整数,它将裁剪所有小数位并舍入到最接近的整数,即 0。因此 B(i,j)= x(i,j)
始终为零。
您的意思可能是 B(i,j)= x(i,j)*255
?
或者更好的是,始终对双精度数进行运算,然后在保存之前转换 int,如果需要的话。
这里有两个问题: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