Image Processing Toolbox    

Displaying Binary Images

To display a binary image, the syntax is

In MATLAB, a binary image is of class logical. Binary images contain only 0's and 1's. Pixels with the value 0 display as black; pixels with the value 1 display as white.

Changing the Display Colors of a Binary Image

You may prefer to invert binary images when you display them, so that 0 values display as white and 1 values display as black. To do this, use the NOT (~) operator in MATLAB. (In this example, a box is drawn around the image to show the image boundary.) For example,

You can also display a binary image using a colormap. For example, the following command displays 0's as red and 1's as blue.

Reading and Writing Binary Images

In certain file formats, a binary image can be stored in a 1-bit format. When you read in a binary image in 1-bit format, MATLAB represents it in the workspace as a logical array.

By default, MATLAB writes binary images as 1-bit images, if the file format supports it.

To verify the bit depth of test.tif, call imfinfo. As you will see, the BitDepth field indicates that it has been saved as a 1-bit image, with the beginning of your output looking something like this.

The Image and Axes Properties of a Binary Image

imshow sets the Handle Graphics properties that control how colors display, as follows:


  Displaying Intensity Images Displaying RGB Images