原文:http://blogs.mathworks.com/steve/2006/02/03/all-about-pixel-colors-part-2/
Let's start by exploring MATLAB's two basic pixel-color display models:
- Matrix element values specify pixel colors directly
- Matrix element values specify pixel colors indirectly, through the figure's colormap
Truecolor images
Here's an illustrative image with just three pixels: red, blue, and yellow.
plane_1 = [1 0 1];
plane_2 = [0 0 1];
plane_3 = [0 1 0];
rgb = cat(3, plane_1, plane_2, plane_3);
size(rgb)
image(rgb)
axis image
title('Truecolor image with one red, one blue, and one yellow pixel')
With truecolor images, changing the colormap has no effect on the image colors displayed.
colormap(hot)
title('Changing the figure colormap does not affect the pixel colors')
Indexed images
If the image CData is two-dimensional, then the CData values are treated as lookup indices into the figure's colormap.
s = load('clown')
image(s.X)
colormap(s.map)
title('Indexed image')
Unlike truecolor images, indexed images are affected by changes in the figure's colormap.
colormap(cool)
title('Indexed image displays incorrectly if you use the wrong colormap')