【问题标题】:Matlab: loading an indexed imageMatlab:加载索引图像
【发布时间】:2015-09-25 09:28:01
【问题描述】:

我想在 matlab 中读取图像并将其转换为索引图像

这是我的代码:

[I map] = imread('image.tif');
I = rgb2ind(I, map);

figure(1);
imagesc(I);axis('equal');

当我刚刚阅读图像时,它看起来不错(但它是 rgb 图像)。然后我将其转换为索引图像,我有以下图片:

这段代码有什么问题?

【问题讨论】:

  • 图片有什么问题?
  • 这不是原始图像。原始图像是一张人的照片。
  • 对于这个问题来说这是相当重要的信息。您应该添加原始图像。
  • 这是我的照片,所以我不想发。我向你保证,这与我在上面看到的彩虹无关。它不是很五颜六色,很暗(但也不是黑白的)。

标签: image matlab rgb indexed


【解决方案1】:

你的语法有点不对劲。这应该有效:

[I, map] = imread('autumn.tif');
[I, map] = rgb2ind(I, map);

figure(1);
image(I);
colormap(map);
axis('equal');

请参阅rgb2ind 的文档。

【讨论】:

    【解决方案2】:

    您的输出是滥用 matlab 函数的结果。

    %read a non-indexed image. I is your RGB image, map is empty
    [I,map] = imread('board.tif');
    %rgb2ind has two output arguments, get both, otherwise your unchanged code
    [I2,map2] = rgb2ind(I, map);
    %Now I2 is a indexed image and map2 the corresponding map
    

    现在您无需应用颜色图即可显示索引图像 I2:

    imagesc(I2)
    

    您的图像包含值 1:n 并且颜色映射 jet 已激活,因此您会看到彩虹。

    使用地图显示正确图像的可能性:

    imagesc(I2)
    colormap(map2)
    

    或显示I,即原始RGB图像

    imagesc(I)
    

    【讨论】:

      猜你喜欢
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 2014-08-29
      相关资源
      最近更新 更多