Besides representing images in the spatial domain (i.e. the Cartesian coordinates), images can also be represented in many other domains. The one that is used most often in image processing is the frequency domain. In order for an image to be represented in the frequency domain, one or more transformation must be performed. Readers have probably seen the 1-Dimensional Fourier transform in a signals and systems course. The 2-Dimensional Fourier transform can be applied to images to obtain their frequency representations. The 2-D Fourier transform is actually an extension to the 1-D case. The transform is given mathematically by
and the inverse 2-D Fourier transform is given by
The discrete Fourier transform (DFT) is a special case of the Fourier transform. It is needed when working with digital images since digital images have a finite number of discrete samples. A digital image is usually obtained from sampling the continuous image. The image pixels are then normally truncated to 8-12 bits per pixel before being processed or displayed. The formula for computing the discrete Fourier transform on an MxN size image is
and the formula for the inverse discrete Fourier transform is
The discrete Fourier transform is a computational intensive operation. It requires (MxN)2 complex multiplications. Fortunately, the computational complexity can be reduced to O(Nlog2N) by using the fast Fourier transform (FFT), which is a fast implementation of the discrete Fourier transform. Listing 4.1 shows the code of a 2-D FFT implementation. The program fft2 reads in an image, performs 2-D FFT or inverse 2-D FFT by calling the 1-D FFT routine for each row and column, and writes the resulting transform to the output file.
fft2 - performs 2D-FFT of an input image
SYNOPSIS
fft2(input_file_name)
fft2(input_file_name, [mrows, ncols])
fft2(input_file_name, mrows, ncols)
mrows | --pads or crops the image to mrowsXncols before transforming |
ncols | --pads or crops the image to mrowsXncols before transforming |
DESCRIPTION
fft2 performs 2D-FFT of an input image. It reads an image,
crops the image if necessary before transforming, and performs
the transformation. The output of the fft2 function is
the frequency transform of the source image in complex data structures.
The Fourier transform of the image is returned to the user and
the magnitude of the Fourier transform is displayed on screen.
This implementation of fft2 makes use of the "fft" function
provided by MATLAB. fft is first applied to the rows of
the image; after that, fft is again applied to the columns of
the row-transformed image.
EXAMPLES
lena_fft2=fft2('LENA.TIF')
This example performs 2D-FFT of LENA (Figure 5.1a) and stores
the frequency transform of the image in the variable "lena_fft2".
ptr_fft2=fft2('PAINTER.TIF')
This example performs 2D-FFT of PAINTER (Figure 5.1b) and stores the frequency transform of the image in the variable "ptr_fft2".
|
|
a. Magnitude spectrum of LENA | b. Magnitude spectrum of PAINTER |
Figure 5.1 Examples of 2D-FFT transformed images
ifft2 - performs inverse 2D-FFT of a Fourier transformed image
SYNOPSIS
ifft2(x, output_file_name)
ifft2(x, output_file_name, [mrows, ncols])
ifft2(x, output_file_name, mrows, ncols)
x | --the frequency transformed image represented by a matrix |
mrows | --pads or crops the image to mrowsXncols before inverse transformation |
ncols | --pads or crops the image to mrowsXncols before inverse transformation |
DESCRIPTION
ifft2 performs 2D-IFFT on a Fourier transformed input
image. x, which is a complex matrix, is the Fouriery-transformed
image. ifft2 reads in the image matrix, crops the image
if necessary before transformation, and performs the inverse transformation.
The output of the ifft2 function is written to the output
file. The format of the output image is TIFF.
This implementation of ifft2 makes use of the "ifft"
function provided by MATLAB. ifft is first applied to the rows
of the image; after that, ifft is again applied to the columns
of the row-transformed image.
EXAMPLES
ifft2(lena_fft2, 'if_lena.tif')
This example performs 2D-IFFT of the previously 2D-FFT transformed
LENA (Figure 5.2a).
ifft2(ptr_fft2, 'if_ptr.tif')
This example performs 2D-IFFT of the previously 2D-FFT transformed
PAINTER (Figure 5.2b)
|
|
a. Restored LENA via 2D-FFT | b. Restored PAINTER via 2D-FFT |
Figure 5.2 Examples of inverse 2D-FFT transformed images