Fast Fourier Transforms (FFT)
Image processing uses processes called "Transforms" to manipulate and compress images. These "transformations" include the Fourier Transform (FT), Walsh Transform, Hadamard Transform, Discrete Cosine Transform (DCT), Haar Transform, and Slant Transform. Of all these transforms, the best known is the Fourier Transform. Deriving the other transforms is usually analogous to the derivation of the FT.
Essentially, the Fourier Transform maps a given function f(x) from the Spatial Domain (of x) into the Frequency Domain (u) using the Fourier Function F(u). This is useful for implementing frequency filters and other processing techniques. For this transformation to work, f(x) must be integratable and continuous over the range (+infinity,-infinity).
The Fourier Transform of f(x) (in one dimension) is given by:
F(u) = ∫ f(x)e-i2*π*ux ∂x
where e represents the natural log and i is the square root of (-1) and thus F(u) is usually a complex function.
When given the Fourier Transform, the original function can be derived using the formula:
f(x) = ∫ F(u)e-i2*π*ux ∂u
When graphed, the spectrum of F(u) is usually graphed. The spectrum is defined as (here with "|" being used in the sense of "absolute value" notation):
|F(u)| = (R2 + I2)0.5
or the absolute value or magnitude of F(u) using the length of the hypotenuse of the complex number when graphed on the Argand plane. In the same way as the one dimensional Fourier Transform, a two dimensional function can also be derived using:
F(u,v) = ∫∫ f(x,y)e-i2*π*(ux+vy) ∂x∂y
and its inverse Fourier Transform:
f(x,y) = ∫∫ F(u,v)ei2π(ux+vy) ∂u∂y
Resolution of Complex numbers in a form suitable for computer manipulation involves invoking Euler's Formula of the form:
e-i2π*ux = cos(2π*ux) - i*sin(2π*ux)
Because computers cannot handle continuous functions, the Fourier Transform is "discretized" over some arbitrary range using the formula:
F(u) = (1/N)∑x=0N-1 f(x)e-i2π*ux/N
One problem with Discrete Fourier Transforms is their computation cost. A one dimensional transform takes n2 cycles to compute: one cycle for each value of x and one for each value of u (since u=x). This cost is even more excessive for two dimensional transforms where we need to cycle through each value of x,y,u and v for a O(n)=n4. These costs make Fourier Transforms difficult to compute for all but very small images (where x is very small).
Fortunately, this computation cost can be reduced using a technique called the Fast Fourier Transform (FFT). Information, discussions, and algorithms for the FFT are available throughout the internet and a selection of links is provided below. Using FFT, the computational effort required to derive the one dimensional FT is now n*log2n and for the two dimensional FT, O(n)=n2log2n--a very dramatic improvement.
To illustrate what Fourier Transforms look like, the left hand image is the image of f(x), and the image on the right its respective Fourier Transform. The 32 and 64 bit images were created using the Discrete Fourier Transform using the code supplied. The 256 bit images were created using the Fast Fourier Transform algorithm. In all cases, the Fourier Transforms were rotated 90 degrees around the origin to shift the image to the center of the display. Note: All the images have been scaled to the same size for consistency of appearance.
|Spatial Images||Fourier Transforms|
A square in a 32x32 pixel image and its associated Fourier Transform.
(Any ghosted images in the white square was caused by JPEG compression. The square should be completely white.)
A square in a 64x64 pixel image and its associated Fourier Transform.
A square in a 256x256 pixel image and its associated Fourier Transform.
A photograph in a 256x256 pixel image and its associated Fourier Transform.
As can be seen from the transforms, the image is a sparsely populated set of data points. Compression is possible by measuring a radius from the middle and then truncating all points outside of the resulting circle. This compression will also lose some higher frequency detail. Alternatively, truncating data points within the middle of the image will result in a loss of low frequency components of the image.
The accompanying source code is copyright the author and all rights are reserved. Please do not reproduce this code for any projects, publications, or assignments without the express permission of the author.
My code (in C) for Fourier Transforms is available.
- The main program controls the file I/O, image parsing, conversion to complex numbers, and image representation functions. Note that the size of the image is hard coded as precompiler directives. The code could also receive the image size as a parameter and utilize calloc calls to create the necessary arrays. Verbose output is available by defining _DEBUG_ as a precompiler directive.
- Global variables and struct definitions and functions supporting Complex number calculations.
- The header file for the Discrete Fourier Transform, Fast Fourier Transform and supporting functions. The reverse function performs a bit-wise reversal of the image array's subscripts. The bit_print function is courtesy of the Al Kelley and Ira Pohl book A Book on C.
- The source code for the functions contained in fft.h