DIP Lab Manual No 09
DIP Lab Manual No 09
Lab Manual No 09
Semester:
Spring 2017
Objectives:-
Which mathematical tools are used to represent an images contents in the 2D frequency
domain?
What is the Fourier transform, what are its main properties, and how is it used in the
context of frequency-domain ltering?
How are image processing lters designed and implemented in the frequency domain?
What are the differences between low-pass and high-pass lters (HPFs)?
What are the differences among ideal, Butterworth, and Gaussian lters?
Introduction:-
Many image processing problems can be expressed in the form of equation of G(u,v).
In a noise removal application, for instance, given f(x,y), the goal, after computing F(u,v), will
be to select H(u,v) such that the desired resulting image,
where F1 is the inverse 2D Fourier transform operation, exhibits a reduction in the noisy
contents present in the original image f(x,y). For certain types of noise, this result could be
achieved using a low-pass Butterworth lter for example.
There are two options for designing and implementing image lters in the frequency domain
using MATLAB and IPT:
Obtain the frequency-domain lter response function from spatial lter convolution mask. The
IPT has a function that does exactly that: freqz2.
Generate lters directly in the frequency domain. In this case, a meshgrid array (of the same size
as the image) is created using the MATLAB function meshgrid.
The FT is a fundamental tool in signal and image processing. In this section, we discuss the
mathematical aspects of 2D transforms in general and then introduce the 2D FT and its main
properties.
Basic Concepts:-
A transform is a mathematical tool that allows the conversion of a set of values to another set of
values, creating, therefore, a new way of representing the same information. In the eld of image
processing, the original domain is referred to as spatial domain, whereas the results are said to lie
in the transform domain. The motivation for using mathematical transforms in image processing
stems from the fact that some tasks are best performed by transforming the input images,
applying selected algorithms in the transform domain, and eventually applying the inverse
transformation to the result. (Figure 2)
Linear 2D transforms can be expressed in generic form in terms of a forward transform T(u,v) as
where u (u = 0,1,2,...,M1) and v (v = 0,1,2,...,N1) are called transform variables, f(x,y) is the
input image, x and y are the row and column dimensions of f(x,y) and r(x,y,u,v) is called the
forward transformation kernel, sometimes expressed as a collection of basis images.
The original image f(x,y) can be recovered by applying the inverse transform of T(u,v):
The 2D Fourier transform of an image is a special case of equations of 1-D Fourier Transform
where,
and
where j =1.
and
In MATLAB:-
The 2D FT and its inverse are implemented in MATLAB by functions fft2 and ifft2,
respectively. 2D FT results are usually shifted for visualization purposes in such a way as to
position the zero-frequency component at the center of the gure. This can be accomplished by
function fftshift. MATLAB also includes function ifftshift, whose basic function is to undo the
results of fftshift.
Example:-
Figure 3 shows an image and its frequency spectrum (the log transformation of the amplitude
component of its 2D FT coefcients). The transformed version of the image clearly bears no
resemblance to the original version. Moreover, it does not provide any obvious visual hints as to
what the original image contents were. Do not bed is courage by these facts, though. As you will
soon see, these apparent limitations of the transformed version of the image will not prevent us
from designing frequency domain lters to achieve specic goals. The resulting image
obtained after applying the inverse transformwill allow us to judge whether those goals were
successfully achieved or not.
MATLAB code:
I = imread(Figure11_04_a.png);
Id = im2double(I);
ft = fft2(Id);
ft_shift = fftshift(ft);
FIGURE 3 (a) Original image (256 256 pixels); (b) Fourier spectrum of the image in (a).
LOW-PASS FILTERING:-
Low-pass lters attenuate the high-frequency components of the Fourier transform of an image,
while leaving the low-frequency components unchanged. The typical overall effect of applying a
low-pass filter (LPF) to an image is a controlled degree of blurring.
FIGURE 4 Original image (a) and its 2D FT spectrum (b); rotated image (c) and its 2D FT
spectrum (d).
Ideal LPF:-
An ideal low-pass lter enhances all frequency components within a specied radius (from the
center of the FT), while attenuating all others. Its mathematical formulation is given as follows:
where
represents the distance between a point of coordinates (u,v) and the origin of the 2D frequency
plan, and D0 is a nonnegative value, referred to as the cutoff frequency.
Figure 5 shows the frequency response plot for an ideal LPF. Figure 6 shows an example image
and its Fourier spectrum. The rings in Figure 6b represent different values for cutoff frequencies
(D0): 8, 16, 32, 64, and 128.
FIGURE 5 Frequency response plot for an ideal LPF: (a) 3D view; (b) 2D view from the top.
FIGURE 6 (a) Original image (256 256 pixels); (b) Fourier spectrum of the image in (a). The
rings represent cutoff frequencies for the low-pass lter examples described later.
Figure 7 shows the results of applying ideal low-pass filters with different cutoff frequencies to
the original image: lower values of D0 correspond to blurrier results. A close inspection of
Figure 7 shows that the filtered images not only are blurry versions of the input imagean
expected outcome, common to all low-pass ltersbut also exhibits noticeable ringing artifacts
that appear because of the sharp transition between passband and stopband in ideal (low-pass)
filters.
FIGURE 7 (a) Original image (256256 pixels); (bf) ideal LPF results for filters with cutoff
frequency corresponding to the radii in Figure 6b, namely, 8, 16, 32, 64, and 128 pixels.
Gaussian LPF:-
A Gaussian low pass filter attenuates high frequencies using a transfer function whose shape is
based on a Gaussian curve. The width of the bell-shaped curve can be controlled by specifying
the parameter , which is functionally equivalent to the cutoff frequency D0 dened previously:
lower values of correspond to more strict filtering, resulting in blurrier results. The smooth
transition between passband and stopband of the Gaussian LPF guarantees that there will be no
noticeable ringing artifacts in the output image. The Gaussian LPF can be mathematically
described as
Figure 8 shows the frequency response plot for a Gaussian LPF. Figure 9 shows the results of
applying Gaussian low-pass lters with different values of .
FIGURE 8 Frequency response plot for a Gaussian LPF: (a) 3D view; (b) 2D view from the top.
FIGURE 9 (a) Original image (256256 pixels); (bf) Gaussian LPF results for lters with
different values for : 5, 10, 20, 30, and 75.
Butterworth LPF:-
where D0 is the cutoff frequency and n is the order of the lter. Figure 10 shows the frequency
response plot for a Butterworth LPF of order n = 4.
FIGURE 10 Frequency response plot for a Butterworth LPF of order n = 4: (a) 3D view; (b) 2D
view from the top.
Figure 11 shows the results of applying Butterworth low-pass lters with n =4 and different
cutoff frequencies to the original image.
HIGH-PASS FILTERING:-
High-pass lters attenuate the low-frequency components of the Fourier transform of an image,
while enhancing the high-frequency components (or leaving them unchanged). The typical
overall effect of applying a high-pass lter to an image is a controlled degree of sharpening.
FIGURE 11 (a) Original image (512512 pixels); (bf) fourth-order Butterworth LPF results for
lters with cutoff frequency corresponding to the radii in Figure 6b, namely, 8, 16, 32, 64, and
128 pixels.
Ideal HPF:-
An ideal high-pass lter attenuates all frequency components with in a specied radius (from the
center of the FT), while enhancing all others. Its mathematical formulation is given as follows:
where
represents the distance between a point of coordinates (u,v) and the origin of the 2D frequency
plan, and D0 is a nonnegative value, referred to as the cutoff frequency (or cutoff radius). Figure
12 shows the frequency response plot for an ideal HPF.
FIGURE 12 Frequency response plot for an ideal HPF: (a) 3D view; (b) 2D view from the top.
Gaussian HPF:-
A Gaussian high pass lter attenuates low frequencies using a transfer function whose shape is
based on a Gaussian curve. The behavior of the lter can be controlled by specifying the
parameter , which is functionally equivalent to the cutoff frequency D0. The Gaussian HPF can
be mathematically described as
FIGURE 13 Frequency response plot for a Gaussian HPF: (a) 3D view; (b) 2D view from the
top.
Butterworth HPF:-
Figure 14 shows the frequency response plot for a Butterworth HPF of order n = 4.
FIGURE 14 Frequency response plot for a Butterworth HPF of order n = 4: (a) 3D view; (b) 2D
view from the top.
Procedure:-
To generate the FT of an image (a 2D function), we use the IPT function fft2, which implements
the FFT algorithm.
1. Load the cameraman image, convert it to double (one of the data classes accepted as an
input to fft2), and generate its FT.
I = imread(cameraman.tif);
Id = im2double(I);
ft = fft2(Id);
To view the spectrum of the image, that is, the amplitude component of the FT results, we must
shift the zero-frequency (DC) component to the center of the image using the fftshift function.
ft_shift = fftshift(ft);
figure,
subplot(1,2,1),imshow(abs(ft_shift),[]),title(Direct remap);
I = imread(eight.tif);
Id = im2double(I);
I_dft = fft2(Id);
[M, N] = size(I);
H = zeros(M, N);
radius = 35;
H(ind) = 1;
Hd = double(H);
To apply the lter to the image, we simply multiply each value of the lter by its corresponding
frequency value in the FT image.
DFT_filt = Hd .* I_dft;
I2 = real(ifft2(DFT_filt));
7. Display both the ltered FT image and the nal ltered image.
figure,imshow(log(1+abs(fftshift(DFT_filt))),[]),title(Filtered
FT);
Gaussian LPF:-
The Gaussian low-pass lter is usually specied by providing a value for the standard deviation
. We can use the distance matrix previously generated to create a Gaussian lter.
sigma = 30;
9. Filter the FT image with the Gaussian low-pass lter and display the ltered image.
I3 = real(ifft2(DFT_filt_gau));
Butterworth LPF:-
The Butterworth low-pass lter is usually specied by providing two parameters: the order of the
lter, n, and the cutoff value, D0. In our implementation of the ideal low-pass lter, earlier in this
tutorial, we set the cutoff value to 35. For comparison purposes, we will use the same value for
our Butterworth lter.
10. Generate a third-order Butterworth lter, where the cutoff value is 35.
D0 = 35;
n = 3;
H_but=1./(1+(dist./D0).(2*n));
11. Filter the image with the Butterworth low-pass lter and display the resulting image.
I4 = real(ifft2(DFT_filt_but));
TASKS:
Write MATLAB code to apply HIGH-PASS filters (Idea, Gaussian, and Butterworth) on
images in frequency domain and show the output results.