Image Processing Toolbox | ![]() ![]() |
Overview
A binary image is an image in which each pixel assumes one of only two discrete values. Essentially, these two values correspond to on
and off
. Looking at an image in this way makes it easier to distinguish structural features. For example, in a binary image, it is easy to distinguish objects from the background.
In the Image Processing Toolbox, a binary image is stored as a two-dimensional matrix of 0's (which represent off
pixels) and 1's (which represent on
pixels). The on
pixels are the foreground of the image, and the off
pixels are the background.
Binary image operations return information about the form or structure of binary images only. To perform these operations on another type of image, you must first convert it to binary (using, for example, the im2bw
function).
Words You Need to Know
An understanding of the following terms will help you to use this chapter. For more explanation of this table and others like it, see Words You Need to Know in the Preface.
Neighborhoods
Most binary image algorithms work with groups of pixels called neighborhoods. A pixel's neighborhood is some set of pixels that are defined by their locations relative to that pixel. The neighborhood can include or omit the pixel itself, and the pixels included in the neighborhood are not necessarily adjacent to the pixel of interest. Different types of neighborhoods are used for different binary operations.
Padding of Borders
If a pixel is near the border of an image, some of the pixels in the image's neighborhood may be missing. For example, if the neighborhood is defined to include the pixel directly above the pixel of interest, then a pixel in the top row of an image will be missing this neighbor.
In order to determine how to process these pixels, the binary image functions pad the borders of the image, usually with 0's. In other words, these functions process the border pixels by assuming that the image is surrounded by additional rows and columns of 0's. These rows and columns do not become part of the output image and are used only as parts of the neighborhoods of the actual pixels in the image. However, the padding can in some cases produce border effects, in which the regions near the borders of the output image do not appear to be homogeneous with the rest of the image. Their extent depends on the size of the neighborhood.
Displaying Binary Images
When you display a binary image with imshow
, by default the foreground (i.e., the on
pixels) is white and the background is black. You may prefer to invert these images when you display or print them, or else display them using a colormap. See Displaying Binary Images for more information.
The remainder of this chapter describes the functions in the Image Processing Toolbox that perform various types of binary image operations. These operations are described in the following sections:
![]() | Noise Removal | Morphological Operations | ![]() |