Lec5 Frequency Filtering
Lec5 Frequency Filtering
COMP4421
Dr. Hao CHEN
Dept. of CSE, HKUST
Filtering in the Frequency Domain
3
Basics about Fourier Transform
4
Fourier Transform
• Jean-Baptiste Joseph Fourier, French
mathematician and physicist (1768-
1830)
• He was orphaned at the age of nine.
• Egyptian expedition with Napoleon I: 1798
Governor of Lower Egypt
• Permanent Secretary of the French
Academy of Sciences: 1822
• Théorie analytique de la chaleur : 1822
(The Analytic Theory of Heat)
5
https://en.wikipedia.org/wiki/Joseph_Fourier
Fourier Transform
6
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Fourier Transform
https://www.youtube.com/watch?v=spUNpyF58BY
7
Fourier Transform
• Why we need Fourier Transform?
• Different views will make it easy to
understand problems
• Transform to frequency from
spatial may decrease the
complexity of problems.
• For some tasks, operation in
frequency domain is much easier.
https://kinder-chen.medium.com/denoising-data-with-fast-fourier-transform-a81d9f38cc4c 8
Fourier Series and Transform
• Fourier Series and Fourier Transform
9
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates what‘s this? what‘s this?
10
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates real imaginary
11
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates real imaginary
Alternative reparameterization:
polar transform
polar
coordinates
how do we compute these?
12
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates real imaginary
Alternative reparameterization:
polar transform
polar
coordinates
polar transform
13
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates real imaginary
Alternative reparameterization:
polar transform
polar
How do you write
coordinates
polar transform these in exponential
form?
14
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates real imaginary
Alternative reparameterization:
polar exponential
coordinates or form
polar transform equivalently how did we get this?
15
Recalling some basics
Complex numbers have two parts:
rectangular
coordinates real imaginary
Alternative reparameterization:
polar exponential
coordinates or form
polar transform equivalently Euler’s formula
The conjugate: 𝐶 ∗ = 𝑅 − 𝑗𝐼 𝑅
Re(𝐶)
17
Fourier series
18
Fourier Series
𝑓(𝑡) is a periodic continuous function with period 𝑇, we have:
Euler’s formula
𝑛=+∞
2𝜋𝑛 2𝜋𝑛 2𝜋𝑛
cos 𝑡 + 𝑗sin( 𝑡)
𝑓 𝑡 = 𝑐𝑛 𝑒 𝑇 𝑡
𝑗
𝑇 𝑇
𝑛=−∞
Where
Coefficient Discrete frequency
1 𝑇/2 2𝜋𝑛
−𝑗 𝑇 𝑡
𝑐𝑛 = න 𝑓 𝑡 𝑒 𝑑𝑡 , 𝑛 = 0, ±1, ±2, …
𝑇 −𝑇/2
19
Basic building block
amplitude phase
sinusoid variable
angular
frequency
Fourier’s claim: Add enough of these to get any periodic signal you want!
20
Examples
How would you generate this function?
= ? + ?
21
Examples
How would you generate this function?
= ? + ?
22
Examples
How would you generate this function?
= ? + ?
23
Examples
How would you generate this function?
= ? + ?
square wave
24
Examples
How would you generate this function?
≈ ? + ?
square wave
=
25
Examples
How would you generate this function?
≈ ? + ?
square wave
=
26
Examples
How would you generate this function?
≈ ? + ?
square wave
=
27
Examples
How would you generate this function?
≈ ? + ?
square wave
=
28
Examples
How would you generate this function?
≈ ? + ?
square wave
29
Examples
30
Examples
magnitude
frequency 31
Fourier transform
32
Fourier Transform
• Fourier Transform Pair in 1D
Linearity ℎ 𝑡 = 𝑎𝑓 𝑡 + 𝑏𝑔 𝑡 ⟷ 𝐻 𝑢 = 𝑎𝐹 𝑢 + 𝑏𝐺(𝑢)
1 𝑢
Scaling ℎ 𝑡 = 𝑓(𝑎𝑡) ⟷ 𝐻 𝑢 = 𝐹( )
𝑎 𝑎
Conjugation ℎ 𝑡 = 𝑓 ∗ 𝑡 ⟷ 𝐻 𝑢 = 𝐹 ∗ (−𝑢)
∞ 𝑊/2
𝐹(𝜇) = න 𝑓(𝑡)𝑒 −𝑗2𝜋𝜇𝑡 𝑑𝑡 = න 𝐴 𝑒 −𝑗2𝜋𝜇𝑡 𝑑𝑡
−∞ −𝑊/2
−𝐴 −𝑗2𝜋𝜇𝑡 𝑊/2 𝐴 𝑗𝜋𝜇𝑊 −𝑗𝜋𝜇𝑊
= 𝑒 = 𝑒 − 𝑒
𝑗2𝜋𝜇 −𝑊/2 𝑗2𝜋𝑊
sin( 𝜋𝜇𝑊)
= 𝐴𝑊
(𝜋𝜇𝑊)
35
Fourier Transform
• Fourier Transform: One Continuous Variable Example
36
Fourier Transform
• Convolution • When consider Fourier Transform:
∞ ∞
• The convolution is denoted by ⋆:
ℑ 𝑓(𝑡) ⋆ ℎ(𝑡) = න න 𝑓(𝜏)ℎ(𝑡 − 𝜏)𝑑𝜏 𝑒 −𝑗2𝜋𝜇𝑡 𝑑𝑡
−∞ −∞
∞
𝑓(𝑡) ⋆ ℎ(𝑡) = න 𝑓(𝜏)ℎ(𝑡 − 𝜏)𝑑𝜏 ∞ ∞
−∞ =න 𝑓(𝜏) න ℎ(𝑡 − 𝜏)𝑒 −𝑗2𝜋𝜇𝑡 𝑑𝑡 𝑑𝜏
−∞ −∞
∞
= න 𝑓(𝜏) 𝐻(𝜇)𝑒 −𝑗2𝜋𝜇𝜏 𝑑𝜏
𝑓(𝑡 − 𝑡0 ) ⟷ 𝑒 −𝑗2𝜋𝑡0 𝜇 𝐹(𝜇) −∞
∞
Spatial domain filter convolution is equivalent to =𝐻(𝜇) න 𝑓(𝜏)𝑒 −𝑗2𝜋𝜇𝜏 𝑑𝜏 =𝐻(𝜇)𝐹(𝜇)
frequency domain multiplication! −∞
37
Fourier Transform
• Convolution Theorem of Continuous Functions
38
Filtering in Frequency Domain
• We will cover:
• Fourier Series and Transform
• Basics
• Fourier series
• Fourier transform
• Discrete Fourier Transform
• Discrete Fourier transform
• 2D discrete Fourier transform for images
• Filtering in Frequency Domain
• Basics
• Smoothing (Lowpass) filters in frequency domain
• Sharpening (Highpass) filters in frequency domain
39
Discrete Fourier Transform (DFT)
40
Discrete Fourier Transform
• Discrete Fourier Transform Pair in 1D
41
Discrete Fourier transform
Where is the connection to the ‘summation of sine waves’ idea?
𝑀−1
1 𝑗2𝜋𝑢𝑥
𝑓 𝑥 = 𝐹 𝑢 𝑒 𝑀 , 𝑥 = 0,1,2, … , 𝑀 − 1
𝑀
𝑢=0
Euler’s formula
43
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Discrete Fourier Transform
• DFT Computation Example
• The first value of 𝐹(𝑢) is
3
𝐹 0 = 𝑓 𝑥 = 𝑓 0 +𝑓 1 +𝑓 2 +𝑓 3 = 11
𝑥=0
𝐹 1 = 𝑓 𝑥 𝑒 −2𝜋 1 𝑥/4
= 1𝑒 0 + 2𝑒 −𝑗𝜋/2 + 4𝑒 −𝑗𝜋 + 4𝑒 −𝑗3𝜋/2
𝑥=0
= −3 + 2𝑗
45
2D Discrete Fourier Transform
• 2-D Discrete Fourier Transform Pair
𝑢 = 0,1,2, … , 𝑀 − 1; 𝜈 = 0,1,2, … , 𝑁 − 1;
𝑓(𝑥, 𝑦) is a digital image of size 𝑀 × 𝑁 Periodicity:
• Translation:
𝑢0 𝑥 𝜈0 𝑦
𝑗2𝜋 𝑀 + 𝑁
𝑓(𝑥, 𝑦)𝑒 ⇔ 𝐹(𝑢 − 𝑢0 , 𝜈 − 𝜈0 )
and 𝑢𝑥0 𝜈𝑦0
−𝑗2𝜋 +
𝑓(𝑥 − 𝑥0 , 𝑦 − 𝑦0 ) ⇔ 𝐹(𝑢, 𝜈)𝑒 𝑀 𝑁
47
2D Discrete Fourier Transform
• Centering the DFT
• 1D case
𝑢 𝑥
0
𝑗2𝜋 𝑀
• 𝑓 𝑥 𝑒 ⇔ 𝐹 𝑢 − 𝑢0
• Let 𝑢0 = 𝑀/2, then
• 𝑓 𝑥 (−1)𝑥 ⇔ 𝐹 𝑢 − 𝑀/2
48
2D Discrete Fourier Transform
• Properties of the 2-D DFT: Fourier Spectrum and Phase
Angle
𝐹 𝑢, 𝑣 = 𝑅 𝑢, 𝑣 + 𝑗𝐼(𝑢, 𝑣)
• Power spectrum
𝑃(𝑢, 𝑣) = |𝐹(𝑢, 𝑣)|2 = 𝑅2 (𝑢, 𝑣) + 𝐼 2 (𝑢, 𝑣)
• Phase angle 𝐼(𝑢, 𝑣)
𝜙(u,v)=arctan
𝑅(𝑢, 𝑣)
49
Power Spectrum
Fourier spectrum
|𝐹(𝑢, 𝑣)| = 𝑅2 (𝑢, 𝑣) + 𝐼2 (𝑢, 𝑣) 1/2
50
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Power Spectrum after Translation, Rotation
Fourier spectrum
|𝐹(𝑢, 𝑣)| = 𝑅2 (𝑢, 𝑣) + 𝐼2 (𝑢, 𝑣) 1/2
51
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Phase Angle after Translation Rotation
Phase angle
𝐼(𝑢, 𝑣)
𝜙(𝑢, 𝑣)=arctan
𝑅(𝑢, 𝑣)
The phase is a measure of displacement of the various sinusoids with respect to their origin.
Sensitive to translation and rotation.
52
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Analysis of Power Spectrum and Phase Angle
𝑀−1 𝑁−1
1 𝑗2𝜋
𝑢𝑥 𝜈𝑦
+
𝑓 𝑥, 𝑦 = 𝐹 𝑢, 𝜈 𝑒 𝑀 𝑁
𝑀𝑁
𝑥=0 𝑦=0
𝑢𝑥 𝜈𝑦
1 𝑗2𝜋 𝑀 + 𝑁
= σ𝑀−1
𝑥=0 σ𝑁−1
𝑦=0 𝐹 𝑢, 𝜈 𝑒 𝑗𝜙(𝑢,𝑣) 𝑒
𝑀𝑁
Weighted summation of sin waves
𝑢𝑥 𝜈𝑦
1 𝑗2𝜋 𝑀 + 𝑁 +𝜙(𝑢,𝑣)
= σ𝑀−1
𝑥=0 σ𝑁−1
𝑦=0 𝐹 𝑢, 𝜈 𝑒
𝑀𝑁
53
Power Spectrum and Phase Angle
54
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Fourier transforms of natural images
original
cheetah phase with zebra amplitude zebra phase with cheetah amplitude 56
2D Discrete Fourier Transform
• 2D Discrete Convolution Theorem
𝑓 ⋆ ℎ 𝑥, 𝑦 ⇔ (𝐻 𝐹)(𝑢, 𝑣)
●
1
(𝑓 ℎ)(𝑥, 𝑦) ⇔
●
(𝐻 ⋆ 𝐹)(𝑢, 𝑣)
𝑀𝑁
57
Filtering in Frequency Domain
• We will cover:
• Fourier Series and Transform
• Basics
• Fourier series
• Fourier transform
• Discrete Fourier Transform
• Discrete Fourier transform
• 2D discrete Fourier transform for images
• Filtering in Frequency Domain
• Basics
• Smoothing (Lowpass) filters in frequency domain
• Sharpening (Highpass) filters in frequency domain
58
Spatial domain filtering
filter kernel
=
Fourier transform inverse Fourier transform
𝑓 𝑥, 𝑦 |𝐹 𝑢, 𝑣 |
Spatial Frequency
60
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Basic Filtering
• The Basic Filtering in the Frequency Domain:
• Modifying the Fourier transform of an image
• Computing the inverse transform to obtain the processed result
61
Basic Filtering
Fourier Filter Function Inverse Fourier
Transform 𝐻(𝑢, 𝑣) Transform
𝐹(𝑢, 𝑣) 𝐻 𝑢, 𝑣 𝐹(𝑢, 𝑣)
Pre-
processing 𝑓 𝑥, 𝑦 ⋆ ℎ(𝑥, 𝑦) ⇔ 𝐹 𝑢, 𝑣 𝐻(𝑢, 𝑣) Post-
processing
Convolution Element-by-element
Filtering Multiplication
𝑓(𝑥, 𝑦)
Input Image 𝑔(𝑥, 𝑦) Enhanced Image
62
Basic Filtering
• The Basic Filtering :
➢ Top row:
Frequency domain filter
transfer functions of
(a) a lowpass filter,
(b) a highpass filter
(c) an offset highpass filter.
➢ Bottom row:
Corresponding filtered
images.
63
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Revisiting blurring
Why does the Gaussian give a nice smooth image, but the box filter give edgy artifacts?
Gaussian Box
filter filter
64
Gaussian blur
65
Box blur
66
More filtering examples
?
filters shown
in frequency-
domain
67
More filtering examples
low-pass
filters shown
band-pass in frequency-
domain
68
More filtering examples
high-pass
69
More filtering examples
high-pass
70
More filtering examples
original image low-pass filter
?
frequency magnitude
71
More filtering examples
original image low-pass filter
frequency magnitude
72
More filtering examples
original image high-pass filter
?
frequency magnitude
73
More filtering examples
original image high-pass filter
frequency magnitude
74
More filtering examples
original image band-pass filter
frequency magnitude
75
More filtering examples
original image band-pass filter
frequency magnitude
76
More filtering examples
original image band-pass filter
frequency magnitude
77
More filtering examples
original image band-pass filter
frequency magnitude
78
Smoothing Filter in Frequency
Domain
ILPF: Ideal Lowpass Filters
GLPF: Gaussian Lowpass Filters
BLPF: Butterworth Lowpass Filter
79
Ideal Lowpass Filters
• Ideal Lowpass Filters (ILPF):
1 if 𝐷(𝑢, 𝑣) ≤ 𝐷0
𝐻(𝑢, 𝑣) = ቊ
0 if 𝐷(𝑢, 𝑣) > 𝐷0
𝐷0 is a positive constant (cutoff frequency) and 𝐷(𝑢, 𝑣) is the distance between
a point (𝑢, 𝑣) in the frequency domain and the center of the P x Q frequency
rectangle
1
2 2
𝑃 2 𝑄
𝐷(𝑢, 𝑣) = (𝑢 − ) + 𝑣 −
2 2
80
Ideal Lowpass Filters
• Ideal Lowpass Filters (ILPF):
81
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Ideal Lowpass Filters
• Image Power:
• We calculate the amount of power a filter “encloses” from the total power 𝑃𝑇 :
𝑃𝑇 = 𝑃(𝑢, 𝑣)
𝑢 𝑣
𝑃 𝑢, 𝑣 = 𝑅 𝑢, 𝑣 2 + 𝐼 𝑢, 𝑣 2
82
Ideal Lowpass Filters
• Image Power:
• A filter, centered at the original of the frequency plane with radius 𝑟,
enclosed 𝛼 precent of power
𝑃 𝑢, 𝑣
𝛼 = × 100%
𝑃𝑇
𝑢 𝑣
Where 𝑢, 𝑣 are summed over the coordinates that lie within the circle or on
its boundary
83
Ideal Lowpass Filters
• Ideal Lowpass Filters (ILPF):
84
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Ideal Lowpass Filters Example
𝐷0 = 10 𝐷0 = 30
𝐷0 = 60 𝐷0 = 160 𝐷0 = 460
85
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Ideal Lowpass Filters
• Ideal Lowpass Filters (ILPF):
86
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Ideal Lowpass Filters
• The sharp cut off in the frequency domain can result in ripples appearing in
87
Gaussian Lowpass Filters
• Gaussian Lowpass Filters (GLPF):
−𝐷 2 (𝑢,𝑣)/2𝜎 2
𝐻(𝑢, 𝑣) = 𝑒
−𝐷 2 (𝑢,𝑣)/2𝐷 2
By letting 𝜎 = 𝐷0 , 𝐻(𝑢, 𝑣) = 𝑒 0
88
Gaussian Lowpass Filters
• Gaussian Lowpass Filters (GLPF) Examples:
89
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Gaussian Lowpass Filters
• Gaussian Lowpass Filters (GLPF) Examples:
90
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Gaussian Lowpass Filter
• Gaussian Lowpass Filters (GLPF) Examples:
91
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Gaussian Lowpass Filter
𝐷0 = 10 𝐷0 = 30
𝐷0 = 60 𝐷0 = 160 𝐷0 = 460
92
Butterworth Lowpass Filter
• Butterworth Lowpass Filter (BLPF):
• This filter does not have a sharp discontinuity
- Instead, it has a smooth transition
• Butterworth Lowpass Filters (BLPF) of order 𝑛 and with cutoff frequency 𝐷0
1
𝐻(𝑢, 𝑣) = 2𝑛
𝐷 𝑢, 𝑣
1+
𝐷0
- 𝐷(𝑢,𝑣) is the distance between a point (𝑢,𝑣) and the center of the frequency plane, and
𝐷0 is a positive constant
93
Butterworth Lowpass Filter
• Butterworth Lowpass Filter (BLPF):
94
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Butterworth Lowpass Filter Example
𝐷0 = 10 𝐷0 = 30
𝐷0 = 60 𝐷0 = 160 𝐷0 = 460
95
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Butterworth Lowpass Filter
• Butterworth Lowpass Filter (BLPF):
96
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Smoothing Filters in Frequency Domain
• ILPF vs. GLPF vs. BLPF:
97
Sharpening Filters in Frequency Domain
IHPF: Ideal Highpass Filters
GHPF: Gaussian Highpass Filters
BHPF: Butterworth Highpass Filter
98
Sharpening Filter in Frequency Domain
• Basic Concept
• Because edges and other abrupt changes in grey levels are associated with
high-frequency components, image sharpening can be achieved by using the
high-pass frequency filtering process.
• The high-pass filter attenuates (suppresses) the low frequency components
without disturbing high-frequency information in the frequency domain.
• Relation between low-pass and high-pass filters:
𝐻ℎ𝑝 𝑢, 𝑣 = 1 − 𝐻𝑙𝑝 (𝑢, 𝑣)
(𝑢, 𝑣) represents position variables in the frequency domain
99
Ideal Highpass Filter
• Ideal High Pass Filter (IHPF):
• A 2-D ideal highpass filter (IHPL) is defined as
0 if 𝐷(𝑢, 𝑣) ≤ 𝐷0
𝐻(𝑢, 𝑣) = ቊ
1 if 𝐷(𝑢, 𝑣) > 𝐷0
where 𝐷(𝑢, 𝑣) is the distance from point (𝑢, 𝑣) to the center of the
frequency plane; 𝐷0 is a non-negative quantity, cutoff frequency
100
Gaussian and Butterworth Highpass Filter
• Gaussian Highpass Filter (GHPL) and Butterworth Highpass Filter
(BHPL)
101
Sharpening Filter in Frequency Domain
102
Sharpening Filter in Frequency Domain
• In Spatial Domain
103
IHPF, GHPF and BHPF
• IHPF vs. GHPF vs. BHPF:
104
IHPF, GHPF and BHPF
• Apply Result
105
IHPF, GHPF and BHPF
• Application with Butterworth Highpass Filter
106
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Sharpening Filter in Frequency Domain
• Unsharp Masking, Highboost Filtering and High-Frequency-Emphasis:
𝑔𝑚𝑎𝑠𝑘 (𝑥, 𝑦) = 𝑓(𝑥, 𝑦) − 𝑓𝐿𝑃 (𝑥, 𝑦)
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑘𝑔𝑚𝑎𝑠𝑘 𝑥, 𝑦
This expression defines unsharp masking when k = 1 and high-boost filtering when k > 1.
108
Sharpening Filter in Frequency Domain
• Image enhancement using high-frequency-emphasis filtering
High-Frequency-
Emphasis Filtering
k1=0.5, k2=0.75
109
Digital Image Processing, by Gonzalez and Woods, Pearson, 2018.
Filtering in Frequency Domain
• We have covered:
• Fourier Series and Transform
• Basics
• Fourier series
• Fourier transform
• Discrete Fourier Transform
• Discrete Fourier transform
• 2D discrete Fourier transform for images
• Filtering in Frequency Domain
• Basics
• Smoothing (Lowpass) filters in frequency domain
• Sharpening (Highpass) filters in frequency domain
110