Image Processing Toolbox | ![]() ![]() |
Displaying Indexed Images
To display an indexed image with imshow
, specify both the image matrix and the colormap.
imshow(X,map)
For each pixel in X
, imshow displays the color stored in the corresponding row of map
. The relationship between the values in the image matrix and the colormap depends on whether the image matrix is of class double
, uint16
, or uint8
. If the image matrix is of class double
, the value 1 points to the first row in the colormap, the value 2 points to the second row, and so on. If the image matrix is of class uint8
or uint16
, there is an offset; the value 0 points to the first row in the colormap, the value 1 points to the second row, and so on. (The offset is handled automatically by the image object, and is not controlled through a Handle Graphics property.)
Each pixel in an indexed image is directly mapped to its corresponding colormap entry. If the colormap contains a greater number of colors than the image, the extra colors in the colormap will simply be ignored. If the colormap contains fewer colors than the image requires, all image pixels over the limits of the colormap's capacity will be set to the last color in the colormap, i.e., if an image of class uint8
contains 256 colors, and you display it with a colormap that contains only 16 colors, all pixels with a value of 15 or higher are displayed with the last color in the colormap.
To change the default behavior of imshow
, set the toolbox preferences. See Setting the Preferences for imshow for more information.
The Image and Axes Properties of an Indexed Image
In most cases, it is not necessary to concern yourself with the Handle Graphics property settings made when you call imshow
. Therefore, this section is not required reading, but rather information for those who really "want to know."
When you display an indexed image, imshow
sets the Handle Graphics properties that control how colors display, as follows:
CData
property is set to the data in X
.CDataMapping
property is set to direct
.CLim
property does not apply, because CDataMapping
is set to direct
. Colormap
property is set to the data in map
.![]() | Displaying Images with imshow | Displaying Intensity Images | ![]() |