【问题标题】:Getting all dark output image获取所有暗输出图像
【发布时间】:2020-07-09 15:28:01
【问题描述】:

如果我在给矩阵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 作为输入。

【问题讨论】:

  • 你的问题不清楚,你想达到什么目的?为什么它不工作?你为什么要删除破坏你的代码的东西?
  • 只需从B = zeros(rows, columns, numberOfColorChannels, 'uint8'); 中删除uint8 即可获得一个 图像。

标签: matlab histogram local


【解决方案1】:

这里有两个问题: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

【讨论】:

  • 天哪,这帮了大忙,但是您能否进一步解释一下为什么要添加这些值 1,2 和 3?
  • 您的输入图像是彩色图像,通常有 3 个通道 - R、G 和 B。在您的代码中 [rows, columns, numberOfColorChannels] = size(x); numberOfColorChannels 将包含 3,因为图像是彩色的。当您进行操作时,您仅在通道 #1 上进行操作,该通道是红色通道,导致红色图像。如果您只在频道#2 上完成此操作,您将获得绿色图像,依此类推。在所有三个上执行此操作会为您提供彩色图像结果。您可能希望对不同的通道进行不同的操作,例如计算每个通道的平均强度等。
  • 详细地说,如果输入图像是仅包含二维的灰度图像,您编写的代码将可以完美运行。
【解决方案2】:

x 是双精度 (im2double),表示其值介于 0 和 1 之间。

您将它存储在一个 0-255 之间的无符号整数 B。作为一个无符号整数,它将裁剪所有小数位并四舍五入到最接近的 int,即 0。因此B(i,j)= x(i,j) 始终为零。

你的意思可能是B(i,j)= x(i,j)*255

或者更好的是,总是对双精度进行操作,然后在保存之前转换 int,如果需要的话。

【讨论】:

  • 好的,所以我删除了 uint8 使 B 加倍,但是当我输出 B 时,它会出现一个红色过滤器。
  • 我试图获得一个输出 B,它显示图像中对比度差的区域的局部直方图均衡
  • 没有红色滤镜,图像只是红色。如您所知,图像有 3 个通道,R、G 和 B。您需要修改代码以索引 3D 矩阵(B(i,j,1) 是红色,但 B(i,j,2) 是蓝色等)。您的代码根本不是为彩色图像设计的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多