problem in subplotting indexed images

1 view (last 30 days)
Its really an interesting thing, the problem is i have two image of lena one is RGB other is gray i converted both to indexed images and with different color maps but when i open the image with subplot the output of both images get gray though i used different color maps and when i open images in different figures the output are in color and other is gray means they r ok with different figures. The code is attached below kindly help me with this any one.
lenatrue = imread('lena.color.tif');
lenagray = imread('lena.pgm');
% Convert RGB to an indexed image with 32 colors
[IND,map] = rgb2ind(lenatrue,322);
[X, map12] = gray2ind(lenagray);
subplot(121)
% figure('Name','Indexed image with 32 Colors')
imagesc(IND)
colormap(map)
imshow(IND,map)
subplot(122)
imshow(X,map12)

Answers (1)

Walter Roberson
Walter Roberson on 30 Jul 2015
colormap() normally affects all images on the same figure. If you are using R2014a or earlier, you cannot change that and you have to take other steps to display the colors properly. If you are using R2014b or later you can have a different colormap for each axes.
colormap(gca, map);
affects the figure in R2014a and earlier but only the one axes in R2014b and later.
Please note that when you use
imagesc(IND)
colormap(map)
imshow(IND,map)
that the imagesc(IND) is computed and the colormap(map) is put into effect, but then the imagesc() is thrown away and replaced by imshow(IND,map) (unless "hold on" is in effect.)
imshow(IND,map) is one of the methods of displaying indexed images so that they are not affected by changes to colormap(). It is a good way to do the displaying unless you want to be able to change the display by calling colormap()

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!