Image Processing Toolbox | ![]() ![]() |
Displaying Intensity Images
To display a intensity (grayscale) image, the most basic syntax is
imshow
displays the image by scaling the intensity values to serve as indices into a grayscale colormap. If I
is double
, a pixel value of 0.0 is displayed as black, a pixel value of 1.0 is displayed as white, and pixel values in between are displayed as shades of gray. If I
is uint8
, then a pixel value of 255 is displayed as white. If I is uint16
, then a pixel value of 65535 is displayed as white.
Intensity images are similar to indexed images in that each uses an m-by-3 RGB colormap, but normally, you will not specify a colormap for an intensity image. MATLAB displays intensity images by using a grayscale system colormap (where R=G=B). By default, the number of levels of gray in the colormap is 256 on systems with 24-bit color, and 64 or 32 on other systems. (See Working with Different Screen Bit Depths for a detailed explanation.)
Another syntax form of imshow
for intensity images enables you to explicitly specify the number of gray levels to use. To display an image I with 32 gray levels, specify a value for n
.
Because MATLAB scales intensity images to fill the colormap range, a colormap of any size can be used. Larger colormaps enable you to see more detail, but they also use up more color slots. The availability of color slots is discussed further in Displaying Multiple Images, and also in Working with Different Screen Bit Depths.
Displaying Intensity Images That Have Unconventional Ranges
In some cases, you may have data you want to display as an intensity image, even though the data is outside the conventional toolbox range (i.e., [0,1] for double
arrays, [0,255] for uint8
arrays, or [0,65535] for uint16
arrays). For example, if you filter an intensity image, some of the output data may fall outside the range of the original data.
To display unconventional range data as an image, you can specify the data range directly, using
If you use an empty matrix ([]
) for the data range, imshow
scales the data automatically, setting low
and high
to the minimum and maximum values in the array. The next example filters an intensity image, creating unconventional range data. imshow
is then called using an empty matrix.
When you use this syntax, imshow
sets the axes CLim
property to [min(J(:)) max(J(:))]
. CDataMapping
is always scaled
for intensity images, so that the value min(J(:))
is displayed using the first colormap color, and the value max(J(:))
is displayed using the last colormap color.
The Image and Axes Properties of an Intensity Image
When you display an intensity image, imshow
sets the Handle Graphics properties that control how colors display, as follows:
CData
property is set to the data in I
.
CDataMapping
property is set to scaled
.
CLim
property is set to [0 1] if the image matrix is of class double
, [0 255] if the matrix is of class uint8
, or [0 65535] if it is of class uint16
.
Colormap
property is set to a grayscale colormap whose values range from black to white.
![]() | Displaying Indexed Images | Displaying Binary Images | ![]() |