Digital Image Processing
Dr Mai Kamal-2022 1
Digital Iamge Processing
Course
By
Dr. Mai Kamal El Den
Lecturer, Computer Science Department,
Faculty of Computers and Artificial Intelligence,
Benha University
Dr Mai Kamal-2022 2
Digital Iamge Processing Course
Dr Mai Kamal-2022 3
Digital Iamge Processing
Course
Teams Link
https://teams.microsoft.com/l/team/19%3az6X9_t1JI66-
A0ZBSXtqyEeY4MaCpjrEIIm2ouxKVuU1%40thread.tacv2/conversations
?groupId=5376f567-69ce-4117-92c0-
21871798fba1&tenantId=ff4a48d6-4b5e-4fd3-8266-7eafc3e6e23e
Dr Mai Kamal-2022 4
Grading Formula
Weights of the Assessments
Final Term Examination 50
Final Oral Exam 10
Midterm Exam 15
Practical Exam 15
Semester Work 10
Dr Mai Kamal-2022 5
Text Book
R. Gonzalez, R. Woods.
Digital Ιmage Processing,
Prentice Hall, 2008.
Third Edition .
Dr Mai Kamal-2022 6
Digital Iamge Processing Course
Lecture 8
Image Enhancement in the frequency
Domain
Dr Mai Kamal DIP 2022
Chapter 4
Frequency Domain
Dr Mai Kamal DIP 2022
Why Frequency Domain?
Why Frequency Domain?
– Many times, image processing tasks can be best
performed in a domain other than the spatial
domain.
– Difficult problems in special domain , easy to
solve in the frequency domain by using Fourier
transform.
– The frequency domain is more convenient for
measurements of systems sensitivity to noise
and parameter variations.
Dr Mai Kamal DIP 2022
Applications of Fourier
Transforms
1-D Fourier transforms are used in Signal Processing
2-D Fourier transforms are used in Image Processing
3-D Fourier transforms are used in Computer Vision
Applications of Fourier transforms in Image
processing: –
– Image enhancement,
– Image restoration,
– Image encoding / decoding,
– Image description
Dr Mai Kamal DIP 2022
Introduction
Fourier Transform: a review
The French mathematician Jean Baptiste Joseph
Fourier.
Published Fourier series in 1822.
Fourier’s ideas were met with skepticism.
Fourier Series:
– Any periodical function can be
expressed as the sum of sines and/or
cosines of different frequencies,
each multiplied by a different
coefficient.
Dr Mai Kamal DIP 2022
Introduction
Fourier Transform: a review
Basic ideas:
A periodic function can
be represented by the
sum of sines/cosines
functions of different
frequencies, multiplied
by a different coefficient.
This is known as
Fourier Transform
Dr Mai Kamal DIP 2022
Introduction
Fourier Transform: a review
For an image, the output of the transformation is
the representation of the image in frequency
space, while the input image is the real space
equivalent.
In the Fourier space image, each point
represents a particular frequency
contained in the real domain image.
Dr Mai Kamal DIP 2022
Introduction
Fourier Transform: a review
A function expressed in either a Fourier Series
or transform can be reconstructed completely
via an inverse process with no loss of
information.
This is one of the important characteristics of
these representations because they allow us to
work in the Fourier Domain and then return to
the original domain.
Dr Mai Kamal DIP 2022
Frequency Filters – Fourier
Transform
Fourier transform (FT)
– Decompose an image into its sine and
cosine components.
– Transform real space images into Fourier or
frequency space images.
– In a frequency space image, each point
represents a particular frequency contained
in the real domain image.
Dr Mai Kamal DIP 2022
Frequency Filters – Fourier
transform
Fourier in Continuous Form:
Dr Mai Kamal DIP 2022
What we need to work
with Image?
1. Fourier transform in Discrete Form.
2. Fourier transform in 2D not 1D.
Dr Mai Kamal DIP 2022
The Discrete Fourier
Transform (DFT)
The Discrete Fourier Transform of 𝑓 𝑥, 𝑦 ,
for 𝑥 = 0, 1, 2…𝑀-1 and 𝑦 = 0,1,2…𝑁-1,
denoted by 𝐹(𝑢, 𝑣), is given by the equation:
M 1 N 1
F (u, v) f ( x, y)e j 2 ( ux / M vy / N )
x 0 y 0
for 𝑢 = 0, 1, 2…𝑀-1 and 𝑣 = 0, 1, 2…𝑁-1.
Dr Mai Kamal DIP 2022
The Inverse DFT
It is really important to note that the
Fourier transform is completely
reversible The inverse DFT is given by:
M 1 N 1
1
f ( x, y )
MN u 0 v 0
F (u, v)e j 2 ( ux / M vy / N )
for x = 0, 1, 2…M-1 and y = 0, 1, 2…N-1
Dr Mai Kamal DIP 2022
How to Perform Fourier
Transform ?
Dr Mai Kamal DIP 2022
Comparison between Frequency
Domain & Spatial Domain
Filters
Spatial (time) domain techniques are
operated directly on pixels of the image.
Frequency domain techniques are based
on modifying the Fourier transform of an
image.
Dr Mai Kamal DIP 2022
Comparison between Frequency
Domain FD& Spatial Domain SD
Filters
Similar jobs can be done in the spatial and frequency
domains.
Filtering in the spatial domain can be easier to
FD order𝒏 𝟒
SD order 𝒏𝟐 𝒍𝒐𝒈𝒏
understand.
Filtering in the frequency domain can be much faster –
especially for large images.
Easier to remove undesirable frequencies in the
frequency domain (i.e., frequency domain filtering).
Faster to perform certain operations in the frequency
domain than in the spatial domain (e.g., convolution)
using the Fast Fourier Transform (FFT).
Dr Mai Kamal DIP 2022
Frequency Filters – Fourier
transform
Frequency Filtering: consists of modifying the
FT of an input image and then finding the IFT
to get the output image.
Mathematically its given by:
G(u,v)= H(u,v)F(u,v)
Dr Mai Kamal DIP 2022
Steps of Frequency Domain
Filter
1. Multiply the input image by (−1) x+y
2. Compute F(u,v)
3. Multiply F(u,v) by a filter function
H(u,v)
4. Compute the inverse DFT
5. Obtain the real part
6. Multiply the real part by (−1) x+y
Dr Mai Kamal DIP 2022
Fourier Transform: shift
It is common to multiply input image
by (-1)x+y prior to computing the FT.
Shift
Dr Mai Kamal DIP 2022
Fourier Transform: shift
Example:
Dr Mai Kamal DIP 2022
How to visualize DFT?
Typically, we visualize the magnitude (spectrum):
|F(u,v)|
Need to apply some “stretching” since the dynamic
range of |F(u,v)| is very large, e.g.:
original image |F(u,v)| |D(u,v)|
Subsequently
mapping the
values to [0, 255]
will further
improve
visualization!
without stretching after stretching
Dr Mai Kamal DIP 2022
Frequency Filters – Fourier
transform
– Example:
FT
(log)
Dr Mai Kamal DIP 2022
Example
For the following image shown:
(a) Compute the 2D-DFT for the marked pixels
𝑀−1 𝑁−1
𝑢𝑥 𝑣𝑦
−2𝜋𝑗( 𝑀 + 𝑁 )
𝐹 𝑢, 𝑣 = 𝑓(𝑥, 𝑦)𝑒
𝑥=0 𝑦=0
Dr Mai Kamal DIP 2022
Example
Answer:
M=4, N=4.
F(x,y)=f(0,0)=232.
F(x,y)=f(3,2)=1.
𝑀−1 𝑁−1
𝐹 0,0 = 𝑓(𝑥, 𝑦)𝑒 −2𝜋𝑗(0+0)
𝑥=0 𝑦=0
F(0,0)=(232+177+82+7+241+18+152+140+156+221+67
+3+100+45+1+103)=1745.
Dr Mai Kamal DIP 2022
Example
Answer:
M=4, N=4.
F(x,y)=f(0,0)=232.
F(x,y)=f(3,2)=1.
𝑀−1 𝑁−1
3𝑥 2𝑦
−2𝜋𝑗( + )
𝐹 3,2 = 𝑓(𝑥, 𝑦)𝑒 4 4
𝑥=0 𝑦=0
𝑭 𝟑, 𝟐
3𝑥 𝑦 3𝑥
−𝜋𝑗( +𝑦)
= σ𝑀−1 𝑁−1
𝑥=0 σ𝑦=0 𝑓(𝑥, 𝑦)𝑒
−2𝜋𝑗( 4 + 2 )
= σ𝑀−1 𝑁−1
𝑥=0 σ𝑦=0 𝑓(𝑥, 𝑦)𝑒 2
Dr Mai Kamal DIP 2022
Example
Answer:
3𝑥
−𝜋𝑗( +𝑦)
𝐹 3,2 =σ𝑀−1 σ𝑁−1
𝑥=0 𝑦=0 𝑓(𝑥, 𝑦)𝑒 2
3
F(3,2)=(232+177𝑒 −𝜋𝑗 +82𝑒 −2𝜋𝑗 +7𝑒 −3𝜋𝑗 +241𝑒 −𝜋𝑗(2) +18
5 7 9
−𝜋𝑗(2) −𝜋𝑗(2) −𝜋𝑗(2)
𝑒 +152𝑒 +140𝑒 +156𝑒 −𝜋𝑗(3) +221𝑒 −𝜋𝑗(4)
9 11 13
+67𝑒 −𝜋𝑗(5) +3𝑒 −𝜋𝑗(6) +100𝑒 −𝜋𝑗(2) +45𝑒 −𝜋𝑗( 2 ) +1𝑒 −𝜋𝑗( 2 )
15
−𝜋𝑗( 2 )
+103𝑒 )= 232 – 177 + 82 – 7 +….
Dr Mai Kamal DIP 2022
Filters in Frequency Domain
Dr Mai Kamal DIP 2022
Frequency Filters
Relationship and comparison with spatial
filters
– Spatial Filtering:
g ( x, y) h( x, y) f ( x, y)
– Frequency Filtering:
G(u, v) H (u, v) F (u, v)
–
h( x, y) H (u, v)
Dr Mai Kamal DIP 2022
Correspondence between FD
and SD filtering:
Special Domain (SD): filtering is given by discrete
convolution and Correlation.
Frequency Domain (FD): Discrete convolution in FD
is equivalent to multiplication
Filtering can be done in either domain.
Dr Mai Kamal DIP 2022
SD VS FD filters
Low pass High pass
Average filters Laplace filters
Dr Mai Kamal DIP 2022
Frequency Filters – Fourier
transform
Image in frequency domain consist of:
– white pixels – low frequencies (details in
image).
– black pixels– high frequencies (not details
in image).
Dr Mai Kamal DIP 2022
Frequency Filters
Frequency
Filter
smoothing Sharping
Dr Mai Kamal DIP 2022
Frequency Filters
Frequencies in an image correspond to
the rate of change in pixel values
– High frequencies
• rapid changes of gray level values.
– Low frequencies
• slow changes of gray level values.
Dr Mai Kamal DIP 2022
Frequency Filters
1. Lowpass filters
– attenuate high frequencies while “passing”
low frequencies.
– Remove high frequency and keep only low frequency.
2. Highpass filters
– attenuate low frequencies while “passing”
high frequencies.
– Remove low frequency and keep high frequency.
Dr Mai Kamal DIP 2022
Low pass & High pass filters in
FD
Low-pass filter: A filter that eliminating high frequencies
while passing low frequencies.- used for blurring
(smoothing).
High-pass filter: A filter that eliminating low frequencies
while passing high frequencies. used for sharpening.
Dr Mai Kamal DIP 2022
1) Low pass – image smoothing
Image smoothing using Frequency Domain
filters
Noise is usually high frequency.
Hence noise removal is usually termed smoothing or
blurring.
Smoothing is achieved by lowpass filters (LPFs).
3 types of LPFs will be studied i.e. Ideal LPF,
Butterworth LPF and Gaussian LPF.
Note/Caution: Image details and edges have high
frequency characteristics.
Dr Mai Kamal DIP 2022
1) Low pass – image smoothing
Smoothing filters:
1.1) Ideal low pass filters (ILPF)
1 if D(u, v) D0
H (u, v)
0 if D(u, v) D0
1.2) Butterworth low pass filters (BLPF)
1
H (u, v)
1 [ D(u, v) / D0 ]2 n
1.3) Gaussian low pass filters (GLPF)
D 2 ( u ,v ) / 2 D0 2
H (u , v) e
Dr Mai Kamal DIP 2022
1.1) 2-D Ideal low pass filter
ILPF
The simplest lowpass filter is ILPF, it (cuts off) all high
frequency components that are at distance greater than a
specified distance: D0 from the center. N
1 if D(u, v) D0
H (u, v) M
Where 0 if D(u, v) D0
– Image size: MxN.
– The size of filter in FD have the same size of the image itself.
– D(u,v) is the distance from (u,v) to the center of the frequency rectangle
– Center of the frequency rectangle: (u,v) = (M/2, N/2)
– Distance to the center: D(u,v) = [(u – M/2)2 + (v – N/2)2]1/2
Dr Mai Kamal DIP 2022
How does ILPF function works?
Simply cut off all high frequency components that are a
specified distance 𝐷0 from the origin of the transform.
Changing the distance changes the behaviour of the filter.
Dr Mai Kamal DIP 2022
How does ILPF function works?
The center of the circle contains the urgent information
or details.
With the increase of D0 the image become better.
Radius total image power %
5 92.0
15 94.6
30 96.4
80 98
230 pixels 99.5
Dr Mai Kamal DIP 2022
Ideal Low Pass Filter Results
Result of filtering
Original with ideal low
image pass filter of
Ringing is a radius 5
characteristics
of ideal Filter
Result of filtering
Result of filtering with ideal low
with ideal low pass filter of
pass filter of radius 30
radius 15
Result of filtering Result of filtering
with ideal low with ideal low
pass filter of pass filter of
radius 80 radius 230
• Ideal low pass filtering is not very practical but they can be implemented
on a computer to study their behavior.
Dr Mai Kamal DIP 2022
Blurring and Ringing Feature of
ILPFs:
The ILPF has sharp cutoffs or discontinuities which cause
ringing.
The ILPF has a sink function behaviour in the Special
Domain.
The center of lobe is the cause for blurring but the outer
smaller lobes cause ringing.
We want to achieve blurring with little ringing.
Dr Mai Kamal DIP 2022
1.2) Butterworth Low Pass
Filter - BLPF:
ILPF transfer function has sharp discontinuities.
BLPF transfer function does not have sharp
discontinuities in order to reduce ringing.
The transfer function of a Butterworth lowpass
filter of order n with cutoff frequency at distance
D0 from the origin is defined as:
1
H (u, v)
1 [ D(u, v) / D0 ]2 n
Dr Mai Kamal DIP 2022
Butterworth low pass filter -
BLPF:
1
H (u, v)
1 [ D(u, v) / D0 ]2 n
Note:
H(U,V) =0.50 (50% from its maximum value of 1) when D(u,v) =D0
Dr Mai Kamal DIP 2022
Butterworth Lowpass Filter
(cont...)
Result of filtering
Original image with Butterworth
filter of order 2
and cutoff radius
Ringing is not visible 5
in any of these
images.
Result of filtering Result of filtering
with Butterworth with Butterworth
filter of order 2 and filter of order 2
cutoff radius 15 and cutoff radius
30
Result of filtering
Result of filtering
with Butterworth
with Butterworth
filter of order 2
filter of order 2
and cutoff radius
and cutoff radius
230
80
Dr Mai Kamal DIP 2022
1.3) Gaussian Lowpass Filters -
GLPF
The transfer function of a Gaussian lowpass filter
is defined as D 2 ( u ,v ) / 2 D 2
H (u , v ) e 0
Note:
The IFT (INVERSE FOURIOUR) of Gaussian is also Gaussian.
Hence there is no ringing effect.
Dr Mai Kamal DIP 2022
Gaussian low pass filter -
GLPF:
Note:
H(U,V) =0.667 when D(u,v) =D0
Dr Mai Kamal DIP 2022
Gaussian Lowpass Filters
(cont…)
Result of
Original filtering with
image Gaussian filter
No ringing with cutoff
radius 5
Result of Result of filtering
filtering with with Gaussian
Gaussian filter filter with cutoff
with cutoff radius 30
radius 15
Result of Result of
filtering with filtering with
Gaussian filter Gaussian filter
with cutoff with cutoff
radius 85 radius 230
Dr Mai Kamal DIP 2022
Lowpass Filters Compared
Result of Result of
filtering with filtering with
ideal low Butterworth
pass filter of filter of order
radius 15 2 and cutoff
radius 15
Result of
filtering with
Gaussian
filter with
cutoff radius
15
Dr Mai Kamal DIP 2022
Lowpass Filtering Examples
A low pass Gaussian filter is used to
connect broken text
Machine recognition systems have
difficulty in reading broken characters.
GLPF with D0 = 80
Dr Mai Kamal DIP 2022
Lowpass Filtering Examples
(cont…)
Different lowpass Gaussian filters used
to remove blemishes in a photograph.
Dr Mai Kamal DIP 2022
Sharping Frequency Filter
Dr Mai Kamal DIP 2022
2)High pass - image Sharpening
Blurring (smoothing) is achieved by attenuating the
HF(high frequency) components of DFT of an image.
(low pass filters).
Sharpening is achieved by attenuating the LF (low
frequency) components of DFT of an image. Where
Edges and fine detail in images are associated with high
frequency components (high pass filters).
High pass filters – only pass the high frequencies, drop the
low ones. High pass frequencies are precisely the reverse
of low pass filters, so:
Hhp(u, v) = 1 – Hlp(u, v)
Dr Mai Kamal DIP 2022
2.1) Ideal High Pass Filters
The ideal high pass filter is given as:
0 if D(u, v) D0
H (u, v)
1 if D(u, v) D0
where D0 is the cut off distance as before
Dr Mai Kamal DIP 2022
Ideal High Pass Filters (cont…)
Results of ideal high Results of ideal high Results of ideal high
pass filtering with D0 pass filtering with D0 pass filtering with D0
= 15 = 30 = 80
Dr Mai Kamal DIP 2022
2.2) Butterworth High Pass
Filters
The Butterworth high pass filter is given
as: 1
H (u, v)
1 [ D0 / D(u, v)]2 n
where n is the order and D0 is the cut off distance
as before
Dr Mai Kamal DIP 2022
Butterworth High Pass Filters
(cont…)
Results of Results of
Butterworth Butterworth
high pass high pass
filtering of filtering of
order 2 with order 2 with
D0 = 15 D0 = 80
Results of Butterworth high pass
filtering of order 2 with D0 = 30
Dr Mai Kamal DIP 2022
2.3) Gaussian High Pass Filters
The Gaussian high pass filter is given as:
D 2 ( u ,v ) / 2 D0 2
H (u , v) 1 e
where D0 is the cut off distance as before
Dr Mai Kamal DIP 2022
Gaussian High Pass Filters
(cont…)
Results of Results of
Gaussian Gaussian
high pass high pass
filtering with filtering with
D0 = 15 D0 = 80
Results of Gaussian high pass
filtering with D0 = 30
Dr Mai Kamal DIP 2022
Highpass Filter Comparison
BF represents a
transition
between the
sharpness
of the IF and the
smoothness of
the GF
Dr Mai Kamal DIP 2022
Highpass Filter Comparison
Results of ideal Results of Butterworth Results of Gaussian high
high pass filtering high pass filtering of pass filtering with D0 =
with D0 = 15 order 2 with D0 = 15 15
Dr Mai Kamal DIP 2022
Next Lecture
LEC.9:IMAGE RESTORATION
(NOISE REMOVAL)
Dr Mai Kamal DIP 2022
Dr Mai Kamal DIP 2022