Matlab 获得全暗输出图像
如果在给定矩阵Matlab 获得全暗输出图像,matlab,histogram,local,Matlab,Histogram,Local,如果在给定矩阵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)
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
我用作输入。x
是双精度(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=0(行、列、numberOfColorChannels,'uint8')中删除uint8
代码>然后你得到一张图像。好的,我去掉了uint8使B加倍,但是当我输出B时,它上面有一个红色的过滤器。我试图得到一个输出B,显示图像中对比度差的区域的局部直方图均衡化。没有红色过滤器,图像只是红色的。如您所知,图像有3个通道,R、G和B。您需要修改代码以索引3D矩阵(B(i,j,1)
为红色,但B(i,j,2)
为蓝色,等等)。您的代码根本不是为彩色图像设计的。这帮了大忙,但您能否进一步解释一下为什么要添加这些值1、2和3?您的输入图像是彩色图像,通常有3个通道-R、G和B。在您的代码中[行、列、NumberOfColorChannel]=大小(x);NumberOfColorChannel将包含3,因为图像是彩色的。当您进行操作时,您只在通道1上进行操作,这是一个红色通道,会产生红色图像。如果你只在第二频道做,你会得到一个绿色的图像等等。在所有这三种情况下都进行此操作会得到彩色图像结果。您可能希望对不同的通道执行不同的操作,如计算每个通道的平均强度等。更详细地说,如果输入图像是仅包含两个维度的灰度图像,那么您编写的代码就可以完美地工作。