Lab 3 Frequency Domain Processing
Lab 3 Frequency Domain Processing
This is really a question that is more for your class instructor. The general idea is that
the image (f(x,y) of size M x N) will be represented in the frequency domain (F(u,v)).
The equation for the two-dimensional discrete Fourier transform (DFT) is:
The concept behind the Fourier transform is that any waveform that can be
constructed using a sum of sine and cosine waves of different frequencies. The
exponential in the above formula can be expanded into sines and cosines with the
variables u and v determining these frequencies.
The inverse of the above discrete Fourier transform is given by the following
equation:
Thus, if we have F(u,v), we can obtain the corresponding image (f(x,y)) using the
inverse, discrete Fourier transform.
Things to note about the discrete Fourier transform are the following:
the value of the transform at the origin of the frequency domain, at F(0,0), is
called the dc component
o F(0,0) is equal to MN times the average value of f(x,y)
o in MATLAB, F(0,0) is actually F(1,1) because array indices in
MATLAB start at 1 rather than 0
the values of the Fourier transform are complex, meaning they have real and
imaginary parts. The imaginary parts are represented by i, which is the square
root of -1
we visually analyze a Fourier transform by computing a Fourier spectrum (the
magnitude of F(u,v)) and display it as an image.
o the Fourier spectrum is symmetric about the origin
the fast Fourier transform (FFT) is a fast algorithm for computing the discrete
Fourier transform.
MATLAB has three functions to compute the DFT:
1. fft -for one dimension (useful for audio)
2. fft2 -for two dimensions (useful for images)
3. fftn -for n dimensions
MATLAB has three functions that compute the inverse DFT:
0. ifft
1. ifft2
2. ifftn
The following table is meant to describe the various steps behind displaying the
Fourier Spectrum.
Create an image
f=zeros(30,30);
with a white f(5:24,13:17)=1;
rectangle and black imshow(f,'InitialMagnification','fit')
background.
To create a finer
sampling of the
F=fft2(f, 256,256);
Fourier transform, F2=abs(F);
you can add zero figure, imshow(F2, [])
padding to fwhen
computing its DFT
The zero-frequency
coefficient is
displayed in the
F2=fftshift(F);
upper left hand F2=abs(F2);
corner. To display figure,imshow(F2,[])
it in the center, you
can use the
function fftshift.
To brighten the
F2=log(1+F2);
display, you can figure,imshow(F2,[])
use a logfunction
To get the results shown in the last image of the table, you can also combine
MATLAB calls as in:
f=zeros(30,30);
f(5:24,13:17)=1;
F=fft2(f, 256,256);
F2=fftshift(F);
figure,imshow(log(1+abs(F2)),[])
Notice in these calls to imshow, the second argument is empty square brackets. This
maps the minimum value in the image to black and the maximum value in the image
to white.
1.3 How does the Discrete Fourier Transform relate to Spatial Domain Filtering?
and, conversely,
the symbol "*" indicates convolution of the two functions. The important thing to
extract out of this is that the multiplication of two Fourier transforms corresponds to
the convolution of the associated functions in the spatial domain.
use absolute
function to get rid
of negatives
figure,imshow(abs(filter_hz) >
0.2*abs(max(filter_hz(:)))); figure,imshow(abs(fdf) > 0.2*abs(max(fdf(:))));
You will notice that both approaches result in a very similar looking filtered image.
1.4 Basic Steps in DFT Filtering
The following summarize the basic steps in DFT Filtering (taken directly from page
121 of Digital Image Processing Using MATLAB):
However, you can also create filters directly in the frequency domain. There are two
commonly discussed filters in the frequency domain:
Lowpass filters:
The corresponding formulas and visual representations of these filters are shown in
the table below. In the formulae, D0 is a specified nonnegative number. D(u,v) is the
distance from point (u,v) to the center of the filter.
Lowpass
Formula Mesh Image
Filter
Ideal
Butterworth
Gaussian
To view the MATLAB calls that were used to create the images in the above table, click on this link.
The following is the result of applying a Gaussian lowpass filter on an image.
The above images were created using two M-files (lpfilter.m and dftuv.m) and the
following MATLAB calls:
footBall=imread('football.jpg');
footBall=footBall(:,:,1); % Grab only the Red component to fake gray
scaling
imshow(footBall)
PQ = paddedsize(size(footBall));
D0 = 0.05*PQ(1);
H = lpfilter('gaussian', PQ(1), PQ(2), D0); % Calculate the LPF
F=fft2(double(footBall),size(H,1),size(H,2)); % Calculate the discrete
Fourier transform of the image
LPF_football=real(ifft2(H.*F)); % multiply the Fourier spectrum by the
LPF and apply the inverse, discrete Fourier transform
LPF_football=LPF_football(1:size(footBall,1), 1:size(footBall,2)); %
Resize the image to undo padding
figure, imshow(LPF_football, [])
% Display the Fourier Spectrum
Fc=fftshift(F); % move the origin of the transform to the center of the
frequency rectangle
S2=log(1+abs(Fc)); % use abs to compute the magnitude (handling
imaginary) and use log to brighten display
figure, imshow(S2,[])
2.2 Highpass Frequency Domain Filters
Highpass filters:
The highpass filter (Hhp ) is often represented by its relationship to the lowpass filter
(Hlp):
Because highpass filters can be created in relationship to lowpass filters, the following
table shows the three corresponding highpass filters by their visual representations:
Lowpass
Mesh Image
Filter
Ideal
Butterworth
Gaussian
To view the MATLAB calls that were used to create the images in the above table,
click on this link.
The above images were created using three M-files (lpfilter.m, dftuv.m,
and hpfilter.m) and the following MATLAB calls
footBall=imread('football.jpg');
footBall=footBall(:,:,1); % Grab only the Red component to fake gray
scaling
imshow(footBall)
PQ = paddedsize(size(footBall));
D0 = 0.05*PQ(1);
H = hpfilter('gaussian', PQ(1), PQ(2), D0); % Calculate the HPF
F=fft2(double(footBall),size(H,1),size(H,2)); % Calculate the discrete
Fourier transform of the image
HPF_football=real(ifft2(H.*F)); % multiply the Fourier spectrum by the
LPF and apply the inverse, discrete Fourier transform
HPF_football=LPF_football(1:size(footBall,1), 1:size(footBall,2)); %
Resize the image to undo padding
figure, imshow(HPF_football, [])
% Display the Fourier Spectrum
Fc=fftshift(F); % move the origin of the transform to the center of the
frequency rectangle
S2=log(1+abs(Fc)); % use abs to compute the magnitude (handling
imaginary) and use log to brighten display
figure, imshow(S2,[])
3. References
Digital Image Processing, Using MATLAB, by Rafael C. Gonzalez, Richard E. Woods, and Steven L.
Eddins
Image Processing Toolbox, For Use with MATLAB (MATLAB's documentation)--available through
MATLAB's help menu or online at:
http://www.mathworks.com/access/helpdesk/help/toolbox/images/