Image Enhancement in Frequency
Domain
Module - 2 : Image Transforms
Typically interested in Fourier Transform (FT)
2
Let us try to attach
“meaning” to the frequency
domain with respect to Image
Processing
3
Spatial Domain Frequency Domain
In image processing:
Instead of time domain: spatial domain
(normal image space)
Frequency domain: space in which each
image value at image position F represents
the amount that the intensity values in image
I vary over a specific distance related to F
4
What is Spatial Frequency?
Spatial frequency of an image refers to
the rate at which the pixel intensities
change
6
Revision of FT
FT decomposes a signal into a set of
sines/cosines of different characteristics like
frequency and phase
FT is perfectly reversible
If Fourier coefficients are multiplied by suitably
chosen weighing function
Certain frequency components can be accentuated
while others are attenuated
Frequency Domain Filtering
Selective enhancement or suppression of
frequency components is termed as Fourier
Filtering or Frequency Domain Filtering
Spatial representation adjacency
relationship between the pixels
Frequency representation clusters the
image data according to their frequency
distribution
Frequency Domain and Images
General comments about relationship between
the frequency components of FT and spatial
characteristics of an image
The slowest varying frequency component ( u = v =
0) corresponds to the average gray level of an
image (origin)
Moving away from the origin low frequencies
correspond to slowly varying components of an
image
Moving further away from the origin higher
frequencies i.e. faster gray level changes (edges of
objects and other abrupt changes such as noise)
9
Frequency Domain and Images
v
(-N/2, -N/2) (-N/2, N/2)
high high
low
u
high high
(N/2, -N/2) (N/2, N/2)
10
Frequency Domain and Images
protrusions
Higher frequencies
correspond to the
faster varying intensity
level changes in the
image. The edges of
objects or the other
components
characterized by the Notice the ±45°
abrupt changes in the components and the
intensity level vertical component
which is slightly off-
corresponds to higher
axis to the left! It
frequencies corresponds to
the protrusion caused
by thermal failure
above.
11
Image Filtering in Frequency
Domain
= G(u,v)
12
A simple Demonstration – Notch filter
Multiply all values of F(u,v) by the filter function (notch filter):
0 if (u , v) ( M / 2, N / 2)
H (u , v)
1 otherwise.
Set F(0,0) to zero (force the average value of an image to
zero) and leave all frequency components of the Fourier
transform untouched.
Low-pass Filtering in Frequency
Domain
Standard forms of low-pass filters (LPF)
Ideal low-pass filter
Butterworth low-pass filter
Gaussian low-pass filter
14
Ideal Low-pass Filter
The simplest low-pass filter is a filter that “cuts off” all
high-frequency components of the Fourier transform that
are at a distance greater than a specified distance D0
from the origin of the transform (D0=cut-off frequency)
Transfer function of an ideal low-pass filter
1 if D(u , v) D0
H (u , v)
0 if D(u , v) D0
where D(u,v) : the distance from point
(u,v) to the center of the frequency rectangle
1
D(u , v) (u M / 2) 2 (v N / 2) 2 2
15
Ideal Low-pass Filter
16
Example Image and its FT
17
Ideal LPF
D0 = 5
Note :
Narrower the D0 = 15 D0 = 30
filter in the
frequency
domain, more
severe are the D0 = 80 D0 = 230
blurring and
ringing!
18
Butterworth Low-pass Filter (BLPF)
Transfer function is given by
1
H (u , v) 2n
D(u , v)
1
D 0
where n = filter order, D0 = cut-off frequency
1
D(u , v) (u M / 2) 2 (v N / 2) 2 2
20
Butterworth Low-pass Filter (BLPF)
1
H (u , v ) 2n
D (u , v )
1
D 0
21
% This code is used to perform Butterworth low-pass filter
clc
im = imread('cameraman.tif');
D0=20; %cut-off frequency
n=1; %order
[M N] = size(im);
% find the centre of the image
cx = round(N/2);
cy = round (M/2);
imf = fftshift(fft2(im));
H = zeros (M, N);
for u = 1:N
for v = 1:M
d = sqrt((u - cx).^2 + (v - cy).^2);
H (u,v) = 1/(1+(d/D0).^(2*n));
end
end
outf = imf .* H;
out = abs (ifft2(outf));
subplot(2,1,1); imshow(im); title ('Original Image');
subplot(2,1,2); imshow(uint8(out)), title('Lowpass Filtered Image (BLPF)');
22
Butterworth Low-pass Filter (BLPF)
The smaller
the value of
D0, the greater
the number of
image
components
eliminated by
the filter
23
BLPF
Order, n=2
Cut-off frequency,
D0=5,15,30,80,and 230
24
BLPF
No ringing for n=1, imperceptible ringing for n=2, ringing
increases for higher orders (getting closer to Ideal LPF)
25
Gaussian Low-pass Filter (GLPF)
Transfer Function
2 2
D
H (u , v) e ( u ,v ) / 2 D0
1
D(u , v) (u M / 2) 2 (v N / 2) 2 2
26
Gaussian Low-pass Filter (GLPF)
27
% This code is used to perform Gaussian low-pass filter
clc
im = imread('cameraman.tif');
D0=10; %cut-off frequency
[M N] = size(im);
% find the centre of the image
cx = round(N/2);
cy = round (M/2);
H = zeros (M, N);
imf = fftshift(fft2(im));
for u = 1:N
for v = 1:M
d = (u - cx).^2 + (v - cy).^2;
H (u,v) = exp(-d/D0.^2);
end
end
outf = imf .* H;
out = abs (ifft2(outf));
subplot(2,1,1); imshow(im); title ('Original Image');
subplot(2,1,2); imshow(uint8(out)), title('Low-pass Filtered Image (GLPF)');
28
GLPF
Cut-off frequency,
D0=5,15,30,80,and 230
No ringing
29
30
Additional Examples of GLPF
31
Additional Examples of GLPF
“Cosmetic” processing
LPF – to produce a
smoother, softer-looking
results from sharp originals
LPF is used in printing, e.g. to smooth fine skin lines in faces. 32
High-pass Filtering in Frequency
Domain
H hp (u , v) 1 H lp (u , v)
Ideal high-pass filter
0 if D(u , v) D0
H (u , v)
1 if D(u , v) D0
Butterworth high-pass filter
1
H (u , v)
1 D0 / D(u , v)
2n
Gaussian high-pass filter
D 2 ( u ,v ) / 2 D02
H (u , v) 1 e
33
Ideal High-pass Filter
0 if D(u , v) D0
H (u , v)
1 if D(u , v) D0
Ideal high-pass filters enhance edges but suffer from ringing artifacts,
just like Ideal LPF. 34
% This code is used to perform Butterworth high-pass filter
clc
im = imread('cameraman.tif');
D0=40; %cut-off frequency
n=1; %order
[M N] = size(im);
% find the centre of the image
cx = round(N/2);
cy = round (M/2);
imf = fftshift(fft2(im));
H = zeros (M, N);
for u = 1:N
for v = 1:M
d = sqrt((u - cx).^2 + (v - cy).^2);
H (u,v) = 1/(1+(D0/d).^(2*n));
end
end
outf = imf .* H;
out = abs (ifft2(outf));
subplot(2,1,1); imshow(im); title ('Original Image');
subplot(2,1,2); imshow(uint8(out)), title(‘High-pass Filtered Image (BHPF)');
35
Butterworth High-pass Filter
1
H (u , v)
1 D0 / D(u , v)
2n
Improved enhanced images with BHPFs
36
Gaussian High-pass Filter
D 2 ( u ,v ) / 2 D02
H (u , v) 1 e
Even smoother results with GHPFs 37
Exercise
Compare
Ideal, Butterworth and Gaussian LPF
Ideal, Butterworth and Gaussian HPF
38
Comments on LPFs
ILPF
The spatial filter
h (x, y) has two
major
characteristics
○ Dominant
component at
the origin
○ Concentric
circular
components
about center
component
Center component is responsible for blurring
Circular components are responsible for the ringing artifacts
39
Comments on LPFs
BLPF
The BLPF with order of 1 does not have any ringing
artifact.
BLPF with orders 2 or more shows increasing ringing
effects as the order increases.
Comments on HPFs
IHPF
The ringing artifacts occur at low cutoff
frequencies
BHPF
Smoother results are obtained in BHPF
when compared IHPF. There is almost no
ringing artifacts
GHPF
Smoother results are obtained in GHPF
when compared BHPF. There is absolutely
no ringing artifacts
Comparison of Ideal, Butterworth and
Gaussian High pass Filters (D0 = 30)
43
The Laplacian in Frequency
Domain
Transfer function
H (u, v) D (u, v)2
where
1
D(u , v) (u M / 2) (v N / 2)
2 2 2
44
The Laplacian in Frequency
Domain
Laplacian-filtered image in spatial
domain
1
f ( x, y ) {H (u, v) F (u, v)}
2
Need to revisit Laplacian in Spatial Domain ?
45
Laplacian In The Frequency
Domain
2-D image of Laplacian
frequency domain
in the frequency
Laplacian in the
domain
frequency domain
Laplacian in the
Inverse DFT of
Zoomed
section of
the image on
the left
compared to
spatial filter
The Laplacian in Frequency
Domain
47
Unsharp Masking
f hp ( x, y ) f ( x, y ) f lp ( x, y )
With
1
f lp ( x, y ) [ H lp (u , v) F (u , v)]
Low pass filter FT of f ( x, y)
High-boost Filtering
Generalization
f hb ( x, y ) Af ( x, y ) f lp ( x, y )
Where A ≥ 1
f hb ( x, y ) ( A 1) f ( x, y ) f hp ( x, y )
Unsharp masking and High-boost
filtering in Frequency Domain
Fhp (u , v) F (u , v) Flp (u , v)
but
Flp (u , v) H lp (u , v) F (u , v)
Direct Implementation by using composite filter
H hp (u , v ) 1 H lp (u , v )
And
H hb (u , v ) ( A 1) H hp (u , v )
50
Example – High-boost
Filtering
51
High-frequency Emphasis
Objective
To accentuate the contribution to
enhancement made by high-frequency
components of an image
Multiply a high-pass filter function by a
constant and add an offset
52
High-Frequency Emphasis
Transfer function
H hfe a bH hp (u , v)
where a 0 and b a
Typical values of a 0.25 to 0.5
Typical values of b 1.5 to 2.0
HFE reduces to HBF when a = (A – 1) and b = 1
When b > 1, high frequencies are emphasized
53
Example – High-Frequency Emphasis
Filtering
Highpass filtering result
Original image
a=0.5, b= 2.0
emphasis result
High frequency
After histogram
equalisation
Highpass Filtering Example
Highpass Filtering Example
Highpass Filtering Example
Highpass Filtering Example
Homomorphic Filtering
Many times, we want to remove shading
effects from an image (i.e., due to uneven
illumination)
Enhance high frequencies
Attenuate low frequencies but preserve fine detail.
59
Homomorphic Filtering
Consider the following model of image formation:
( x, y ) i ( x, y ) r ( x, y )
fIn general, I (x,y): illumination
r(x, y): reflection
The illumination component i (x, y) varies slowly and
affects low frequencies mostly.
The reflection component r (x, y) varies faster and
affects high frequencies mostly.
IDEA: separate low frequencies due to i (x, y)
from high frequencies due to r (x,y)
Homomorphic Filtering
61
Homomorphic Filtering
c ( D 2 ( u ,v ) / D02 )
H (u , v) ( H L )[1 e ] L
L <1 H >1
Attenuate the contribution
Attenuate the
made by illumination
contribution made by (low
frequencies)
illumination and amplify the
and amplify
contribution
the contributionmade
madeby
by reflectance
reflectance (high frequencies)
Example - Homomorphic
Filtering
L =0.5 H =2.0
63
Example - Homomorphic
Filtering
L 0.25
H 2
c 1
D0 80
A Final Comment
Similar jobs can be done in the spatial and
frequency domains
Filtering in the spatial domain can be
easier to understand
Filtering in the frequency domain can be
much faster – especially for large images
Why Frequency Domain?
-One Reason
66