Matlab,rgb2gray给出彩色图像作为输出

dd2*_*210 3 matlab image-processing

您能否澄清一下,Matlab 中的“rgb2gray”函数如何工作?

u=imread('C:\im1.jpg');
image(rgb2gray(u));
Run Code Online (Sandbox Code Playgroud)

原图信息:

答案=

       Filename: 'C:\im1.jpg'
    FileModDate: '09-Mar-2014 20:30:14'
       FileSize: 8653
         Format: 'jpg'
  FormatVersion: ''
          Width: 320
         Height: 240
       BitDepth: 24
      ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
   CodingMethod: 'Huffman'
  CodingProcess: 'Sequential'
        Comment: {}
Run Code Online (Sandbox Code Playgroud)

我收到输出图像,但它绝对不是灰度..只是一些颜色非常明亮的图像。我在文档中找不到任何线索 - 也许问题与原始图片的颜色深度有关。

谢谢!

Lui*_*ndo 5

即使您有灰色图像(2D 数组),显示的颜色也将取决于您使用的颜色图。您应该设置灰色颜色图:

u = imread('C:\im1.jpg');
image(rgb2gray(u));
colormap(gray(256)) %// u is uint8, so 256 levels
Run Code Online (Sandbox Code Playgroud)

详细信息请参阅colormap文档

  • +1 鉴于默认颜色图通常是“jet”,那就这样了。这就是为什么我喜欢“imshow”。 (2认同)