Image Processing Toolbox User's Guide Previous page   Next Page

Applications of the Fourier Transform

This section presents a few of the many image processing-related applications of the Fourier transform.

Frequency Response of Linear Filters

The Fourier transform of the impulse response of a linear filter gives the frequency response of the filter. The function freqz2 computes and displays a filter's frequency response. The frequency response of the Gaussian convolution kernel shows that this filter passes low frequencies and attenuates high frequencies.

Frequency Response of a Gaussian Filter

See Linear Filtering and Filter Design for more information about linear filtering, filter design, and frequency responses.

Fast Convolution

A key property of the Fourier transform is that the multiplication of two Fourier transforms corresponds to the convolution of the associated spatial functions. This property, together with the fast Fourier transform, forms the basis for a fast convolution algorithm.

To illustrate, this example performs the convolution of A and B, where A is an M-by-N matrix and B is a P-by-Q matrix:

  1. Create two matrices.
  2. Zero-pad A and B so that they are at least (M+P-1)-by-(N+Q-1). (Often A and B are zero-padded to a size that is a power of 2 because fft2 is fastest for these sizes.) The example pads the matrices to be 8-by-8.
  3. Compute the two-dimensional DFT of A and B using fft2.
  4. Multiply the two DFTs together.
  5. Compute the inverse two-dimensional DFT of the result using ifft2.
  1. The following code performs steps 3, 4, and 5 in the procedure.

  1. Extract the nonzero portion of the result and remove the imaginary part caused by roundoff error.

Locating Image Features

The Fourier transform can also be used to perform correlation, which is closely related to convolution. Correlation can be used to locate features within an image; in this context correlation is often called template matching.

This example illustrates how to use correlation to locate occurrences of the letter "a" in an image containing text:

  1. Read in the sample image.
  2. Create a template for matching by extracting the letter "a" from the image.
  1. You can also create the template image by using the interactive version of imcrop, using the pixval function to determine the coordinates of features in an image.

    The following figure shows both the original image and the template.

Image (left) and the Template to Correlate (right)

  1. Compute the correlation of the template image a with the original image bw by rotating the template image by 180o and then using the FFT-based convolution technique described in Fast Convolution. (Convolution is equivalent to correlation if you rotate the convolution kernel by 180o.) To match the template to the image, use the fft2 and ifft2 functions.
  1. The following image shows the result of the correlation. Bright peaks in the image correspond to occurrences of the letter.

Correlated Image

  1. To view the locations of the template in the image, find the maximum pixel value and then define a threshold value that is less than this maximum. The locations of these peaks are indicated by the white spots in the thresholded correlation image. (To make the locations easier to see in this figure, the thresholded image has been dilated to enlarge the size of the points.)

Correlated, Thresholded Image Showing Template Locations

Previous page  Discrete Fourier Transform Discrete Cosine Transform Next page

© 1994-2005 The MathWorks, Inc.