如果不同的调色板,映射的imshow在子图中不起作用

时间:2013-06-22 13:34:24

标签: image matlab matlab-figure color-mapping

我发现显然,imshow函数的映射版本在子图中不起作用。这是设计吗?

以下脚本

rgb=imread('../FruitSample_small.png');
[ind,map]=rgb2ind(rgb,4);
figure
imshow(ind,map)
figure
subplot(5,1,1);
imshow(ind,map)
subplot(5,1,2);
imshow(ind==0)
subplot(5,1,3);
imshow(ind==1)
subplot(5,1,4);
imshow(ind==2)
subplot(5,1,5);
imshow(ind==3)

产生以下结果

enter image description here

即。映射版看起来很黑。如果我只绘制映射版本(5次),它看起来不错。即随后的绘图显然改变了调色板。

如何在同一个数字上绘制所有这5幅图像呢?

1 个答案:

答案 0 :(得分:1)

Colormap是图的属性,而不是轴。对imshow的第二次调用会重置整个数字的ColormapHere是针对该问题的更多信息和Matlab文件交换解决方案。如果您下载该链接中描述的功能freezeColors,则可以在此代码中使用它。

rgb=imread('peppers.png'); % example image included in matlab
[ind,map]=rgb2ind(rgb,4);
figure
imshow(ind,map)

figure
subplot(5,1,1);
imshow(ind,map)
freezeColors % keep colors the same after other subplots are displayed
subplot(5,1,2);
imshow(ind==0)
freezeColors
subplot(5,1,3);
imshow(ind==1)
subplot(5,1,4);
imshow(ind==2)
subplot(5,1,5);
imshow(ind==3)

由此产生的第二个数字将如下所示:

fixed colors subplots example