Image Processing Toolbox    

Binary Image Operations


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.

Words
Definitions
Background
The set of black (or off) pixels in a binary object.
Binary image
An image containing only black and white pixels. In MATLAB, a binary image is represented by a uint8 or double logical matrix containing 0's and 1's (which usually represent black and white, respectively). A matrix is logical when its "logical flag" is turned "on." We often use the variable name BW to represent a binary image in memory.
Connected component
A set of white pixels that form a connected group. A connected component is "8-connected" if diagonally adjacent pixels are considered to be touching, otherwise, it is "4-connected." In the context of this chapter, "object" is a synonym for "connected component."
Foreground
The set of white (or on) pixels in a binary object.
Morphology
A broad set of binary image operations that process images based on shapes. Morphological operations apply a structuring element to an input image, creating an output image of the same size. The most basic morphological operations are dilation and erosion.
Neighborhood
A set of pixels that are defined by their locations relative to the pixel of interest. In binary image operations, a neighborhood can be defined by a structuring element or by using the criterion for a 4- or 8-connected neighborhood.
Object
A set of white pixels that form a connected group. In the context of this chapter, "object" and "connected component" are basically equivalent. See "Connected component" above.
Structuring element
A matrix used to define a neighborhood shape and size for binary image operations, including dilation and erosion. It consists of only 0's and 1's and can have an arbitrary shape and size. The pixels with values of 1 define the neighborhood. By choosing a proper structuring element shape, you can construct a morphological operation that is sensitive to specific shapes.

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