【问题标题】:How do I display the red channel of an image in Matlab?如何在 Matlab 中显示图像的红色通道?
【发布时间】:2011-04-02 14:24:16
【问题描述】:

我有一个代表 RGB 图像的 3D 矩阵 im。我可以的

imshow(im)

显示图像。

我想一次只显示一个 RGB 通道:我想显示红色通道并且我希望它显示为红色。

我试过了

imshow(im(:,:,1))

但它显示的是灰度图像(这不是我想要的)。

如何显示红色通道并使其显示为红色?

【问题讨论】:

  • 这里重要的是,如果要显示彩色图像,请确保它是 3 维的。如果你做 im(:,:,1),你只剩下一个维度。

标签: image matlab rgb graphics


【解决方案1】:

我有三个建议给你。

1. 使用imagesc 函数并选择红色调色板。

2. 清除其他颜色通道:im(:,:,2:3) = 0; imshow(im);

3.ind2rgb 函数与您相应构建的颜色图一起使用。

【讨论】:

    【解决方案2】:

    你的意思是你只想提取红色? 使用 im(:,:,1) 仅将红色通道与 3D 图像分离并将其转换为 2D 图像。 试试这个简单的代码:

    im=imread('example.jpg');
    im_red=im(:,:,1);
    im_gray=rgb2gray(im);
    im_diff=imsubtract(im_red,im_gray);
    imshow(im_diff);
    

    【讨论】:

      【解决方案3】:

      试试这个:

      % display one channel only
      clear all;
      
      im=imread('images/DSC1228L_512.jpg');
      im_red = im;
      im_green = im;
      im_blue = im;
      
      % Red channel only
      im_red(:,:,2) = 0; 
      im_red(:,:,3) = 0; 
      figure, imshow(im_red);
      
      % Green channel only
      im_green(:,:,1) = 0; 
      im_green(:,:,3) = 0; 
      figure, imshow(im_green);
      
      % Blue channel only
      im_blue(:,:,1) = 0; 
      im_blue(:,:,2) = 0; 
      figure, imshow(im_blue);
      

      【讨论】:

        【解决方案4】:

        试试这个

        I = imread('exemple.jpg');
        
        %Red component
        R = I(:,:,1);
        image(R), colormap([[0:1/255:1]', zeros(256,1), zeros(256,1)]), colorbar;
        
        %Green Component
        G = I(:,:,2);
        figure;
        image(G), colormap([zeros(256,1),[0:1/255:1]', zeros(256,1)]), colorbar;
        
        %Blue component
        B = I(:,:,3);
        figure;
        image(B), colormap([zeros(256,1), zeros(256,1), [0:1/255:1]']), colorbar;
        

        【讨论】:

          【解决方案5】:

          为了获得更好的视图,您可以计算并显示纯色。公式 Rp = Rc / (Rc + Gc + Bc子>)。还有一个红色的代码示例:

          imagesc(im(:,:,1) ./ (im(:,:,1) + im(:,:,2) + im(:,:,3)))
          

          这将使颜色显示更清晰,因为其他颜色已被过滤掉。

          我会尝试用一个例子来说明它:

          原图:

          图片的红色通道(im(:,:,1)):

          纯红色:

          【讨论】:

            猜你喜欢
            • 2014-05-27
            • 2020-03-18
            • 2017-11-28
            • 2013-06-04
            • 2012-04-12
            • 1970-01-01
            • 2023-04-05
            • 2020-10-08
            • 2015-12-29
            相关资源
            最近更新 更多