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.

To change the default behavior of imshow, set the toolbox preferences. See Setting the Preferences for imshow for more information.

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 [low high]. CDataMapping is always scaled for intensity images, so that low corresponds to the first row of the grayscale colormap and high corresponds to the last row.

The Image and Axes Properties of an Intensity 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 intensity image, imshow sets the Handle Graphics properties that control how colors display, as follows:


 Displaying Indexed Images Displaying Binary Images