2

I found that apparently, a mapped version of imshow function does not work in subplot. Is this by design?

The following script

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)

produces the following result

enter image description here

i.e. mapped version looks black. If I plot mapped version only (5 times) it looks ok. I.e. subsequent plotting apparently change the palette.

How to plot all these 5 images on same figure then?

4

1 回答 1

1

Colormap是图形的属性,而不是轴。对 imshow 的第二次调用会重置Colormap整个图形的 。是一些更多信息和解决问题的 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)

生成的第二个图形将如下所示:

固定颜色子图示例

于 2013-06-22T16:04:40.420 回答