Image Processing Toolbox | ![]() ![]() |
Applications
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.
Figure 8-7: The 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.
Suppose that A
is an M-by-N matrix and B
is a P-by-Q matrix. The convolution of A
and B
can be computed using the following steps:
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.)
A
and B
using fft2
.
ifft2
, compute the inverse two-dimensional DFT of the result from step 3.
A = magic(3); B = ones(3); A(8,8) = 0; % Zero-pad A to be 8-by-8 B(8,8) = 0; % Zero-pad B to be 8-by-8 C = ifft2(fft2(A).*fft2(B)); C = C(1:5,1:5); % Extract the nonzero portion C = real(C) % Remove imaginary part caused by roundoff error C = 8.0000 9.0000 15.0000 7.0000 6.0000 11.0000 17.0000 30.0000 19.0000 13.0000 15.0000 30.0000 45.0000 30.0000 15.0000 7.0000 21.0000 30.0000 23.0000 9.0000 4.0000 13.0000 15.0000 11.0000 2.0000
The FFT-based convolution method is most often used for large inputs. For small inputs it is generally faster to use imfilter
.
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.
For instance, suppose you want to locate occurrences of the letter "a" in an image containing text. This example reads in text.tif
and creates a template image by extracting a letter "a" from it.
bw = imread('text.tif'); a=bw(59:71,81:91); %Extract one of the letters "a" from the image. imshow(bw); figure, imshow(a);
Figure 8-8: An Image (left) and the Template to Correlate (right)
The correlation of the image of the letter "a" with the larger image can be computed by first rotating the image of "a" by 180o and then using the FFT-based convolution technique described above. (Note that convolution is equivalent to correlation if you rotate the convolution kernel by 180o.) To match the template to the image, you can use the fft2
and ifft2
functions.
C = real(ifft2(fft2(bw) .* fft2(rot90(a,2),256,256))); figure, imshow(C,[])%Display, scaling data to appropriate range. max(C(:)) %Find max pixel value in C. ans = 51.0000 thresh = 45; %Use a threshold that's a little less than max. figure, imshow(C > thresh)%Display showing pixels over threshold.
Figure 8-9: A Correlated Image (left) and its Thresholded Result (right)
The left image above is the result of the correlation; bright peaks correspond to occurrences of the letter. The locations of these peaks are indicated by the white spots in the thresholded correlation image shown on the right.
Note that you could also have created the template image by zooming in on the image and using the interactive version of imcrop
. For example, with text.tif
displayed in the current figure window, enter
To determine the coordinates of features in an image, you can use the pixval
function.
![]() | Discrete Fourier Transform | Discrete Cosine Transform | ![]() |