Image Processing Toolbox | ![]() ![]() |
Displaying Indexed Images
To display an indexed image with imshow
, specify both the image matrix and the colormap.
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.)
imshow
directly maps each pixel in an indexed image to its corresponding colormap entry. If the colormap contains a greater number of colors than the image, imshow
ignores the extra colors in the colormap. If the colormap contains fewer colors than the image requires, imshow
sets all image pixels over the limits of the colormap's capacity to the last color in the colormap. For example, 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.
The Image and Axes Properties of an Indexed Image
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 | Displaying Intensity Images | ![]() |