Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
University of Ioannina - Department of Computer Science and Engineering
Filtering in the Frequency Domain
(Fundamentals)
Digital Image Processing
Christophoros Nikou
2
C. Nikou – Digital Image Processing (E12)
Filtering in the Frequency Domain
Filter: A device or material for suppressing or
minimizing waves or oscillations of certain
frequencies.
Frequency: The number of times that a periodic
function repeats the same sequence of values
during a unit variation of the independent variable.
Webster’s New Collegiate Dictionary
3
C. Nikou – Digital Image Processing (E12)
Jean Baptiste Joseph Fourier
Fourier was born in Auxerre,
France in 1768.
– Most famous for his work “La Théorie Analytique de la Chaleur” published in 1822.
– Translated into English in 1878: “The Analytic Theory of Heat”.
Nobody paid much attention when the work was first published.
One of the most important mathematical theories in modern engineering.
4
C. Nikou – Digital Image Processing (E12)
The Big Idea
=
Any function that periodically repeats itself can
be expressed as a sum of sines and cosines of
different frequencies each multiplied by a
different coefficient – a Fourier series
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
5
C. Nikou – Digital Image Processing (E12)
1D continuous signals
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
0
0
,( )
0 otherwise
x xx x
• It may be
considered both as
continuous and
discrete.
• Useful for the
representation of
discrete signals
through sampling
of continuous
signals.0 0( ) ( ) ( )f x x x dx f x
6
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
( ) ( )T
n
S t t n T
[ ] ( ) ( ) ( ) ( ) ( ) ( )T
n n
x n x t S t x t t n T x n T t n T
Impulse train function
7
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
[ ] ( ) ( )Tx n x t S t
( ) ( )n
x t t n T
( ) ( )n
x n T t n T
8
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • The Fourier series expansion of a periodic
signal f (t).
2
( )j nt
Tn
n
f t c e
/ 2 2
/ 2
1( )
Tj nt
Tn
T
c f t e dtT
9
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • The Fourier transform of a continuous
signal f (t).
2( ) ( ) j tF f t e dt
2( ) ( ) j tf t F e d
• Attention: the variable is the frequency (Hz) and
not the radial frequency (Ω=2πμ) as in the Signals
and Systems course.
10
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
/ 2
sin( )( ) ( ) ( )
( )W
Wf t P t F W
W
11
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Convolution property of the FT.
( )* ( ) ( ) ( )
( )* ( ) ( ) ( )
f t h t f h t d
f t h t F H
( ) ( ) ( )* ( )f t h t F H
12
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Intermediate result
− The Fourier transform of the impulse train.
1( )
n n
nt n T
T T
• It is also an impulse train in the frequency
domain.
• Impulses are equally spaced every 1/ΔΤ.
13
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
[ ] ( ) ( )Tx n x t S t
( ) ( )n
x t t n T
( ) ( )n
x n T t n T
Sampling
14
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Sampling
− The spectrum of the discrete signal consists of
repetitions of the spectrum of the continuous
signal every 1/ΔΤ.
− The Nyquist criterion should be satisfied.
( ) ( )
1( ) [ ] ( )
n
f t F
nf n T f n F F
T T
15
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
Nyquist theorem
max
12
T
16
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
Oversampling
Undersampling
Aliasing appears
Critical sampling with
the Nyquist frequency
FT of a continuous signal
17
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Reconstruction (correct sampling).
( ) ( ) ( )F F H
( ) ( )* sint
f t f t T cT
18
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Reconstruction
− Provided a correct sampling, the continuous
signal may be perfectly reconstructed by its
samples.
( )( ) ( ) sinc
n
t n Tf t f n T
n T
19
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
• Aliasing, the
reconstruction of the
continuous signal is
not correct.
20
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
Aliased signal
21
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • The Fourier transform of a sampled (discrete)
signal is a continuous function of the frequency.
1( )
n
nF F
T T
• For a N-length discrete signal, taking N samples of
its Fourier transform at frequencies:
provides the discrete Fourier transform (DFT) of
the signal.
0,1, .., 1,k k Nk
N T
22
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • DFT pair of signal f [n] of length N.
21
0
21
0
0 1
0 1
[ ] [ ] ,
1[ ] [ ] ,
nkN jN
n
nkN jN
n
k N
n N
F k f n e
f n F k eN
23
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Property
– The DFT of a N-length f [n] signal is periodic
with period N.
[ ] [ ]F k N F k
– This is due to the periodicity of the complex
exponential:
2 2
nn
j jn nN NN Nw e w e
24
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Property: sum of complex exponentials
0
1, ,1
0, otherwise
Nkn
N
n
k rN rw
N
The proof is left as an exercise.
2j
NNw e
25
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • DFT pair of signal f [n] of length N may be
expressed in matrix-vector form.
1
0
1
0
0 1
0 1
[ ] [ ] ,
1[ ] [ ] ,
Nnk
N
n
Nnk
N
n
k N
n N
F k f n w
f n F k wN
2j
NNw e
26
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
F = Af
[0], [1],..., [ 1] , [0], [1],..., [ 1]T T
f f f N F F F N f = F =
0 1 2 10 0 0 0
0 1 2 11 1 1 1
0 1 2 11 1 1 1
N
N N N N
N
N N N N
NN N N N
N N N N
w w w w
w w w w
w w w w
A
27
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
Example for N=4
1 1 1 1
1 1
1 1 1 1
1 1
j j
j j
A
28
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
The inverse DFT is then expressed by:
-1f = A F
*0 1 2 1
0 0 0 0
0 1 2 11 1 1 1
1 *
0 1 2 11 1 1 1
1 1
TN
N N N N
NT
N N N N
NN N N N
N N N N
w w w w
w w w w
N N
w w w w
A A
This is derived by the complex exponential sum
property.
29
C. Nikou – Digital Image Processing (E12)
Linear convolution
is of length N=N1+N2-1=4
1 2[ ] {1, 2, 2}, [ ] {1, 1}, 3, 2f n h n N N
[ ] [ ]* [ ] [ ] [ ]m
g n f n h n f m h n m
30
C. Nikou – Digital Image Processing (E12)
Linear convolution (cont.)
1 2[ ] {1, 2, 2}, [ ] {1, 1}, 3, 2f n h n N N
[ ] 1 2 2 [ ]
0 [0 ] 1 1 1
1 [1 ] 1 1 1
2 [2 ] 1 1 0
3 [3 ] 1 1 2
f m g n
n h m
n h m
n h m
n h m
[ ] [ ]* [ ] [ ] [ ]m
g n f n h n f m h n m
[ ] {1, 1, 0, 2}g n
31
C. Nikou – Digital Image Processing (E12)
Circular shift
• Signal x[n] of length N.
• A circular shift ensures that the resulting
signal will keep its length N.
• It is a shift modulo N denoted by
[( ) ] [( )mod ]Nx n m x n m N
• Example: x[n] is of length N=8.
8[( 2) ] [( 2) ] [6]Nx x x
8[(10) ] [(10) ] [2]Nx x x
32
C. Nikou – Digital Image Processing (E12)
Circular convolution
The result is of length
1 2[ ] {1, 2, 2}, [ ] {1, 1}, 3, 2f n h n N N
[ ] [( ) ]N
m
f m h n m
g[n]=f [n]h[n]
1 2max , 3N N N
Circular shift modulo N
33
C. Nikou – Digital Image Processing (E12)
Circular convolution (cont.)
1 2[ ] {1, 2, 2}, [ ] {1, 1}, 3, 2f n h n N N
[ ] 1 2 2 [ ]
0 [(0 ) ] 1 1 1 1
1 [(1 ) ] 1 1 1
2 [(2 ) ] 1 1 0
N
N
N
f m g n
n h m
n h m
n h m
[ ] { 1, 1, 0,}g n
[ ] [( ) ]N
m
f m h n m
g[n]=f [n]h[n]
34
C. Nikou – Digital Image Processing (E12)
DFT and convolution
[ ] [ ] [ ]G k F k H k g[n]=f [n]h[n]
• The property holds for the circular
convolution.
• In signal processing we are interested in
linear convolution.
• Is there a similar property for the linear
convolution?
35
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
[ ] [ ] [ ]G k F k H k g[n]=f [n]h[n]
• Let f [n] be of length N1 and h[n] be of length N2.
• Then g[n]=f [n]*h[n] is of length N1+N2-1.
• If the signals are zero-padded to length N=N1+N2-1
then their circular convolution will be the same as
their linear convolution:
[ ] [ ]* [ ] [ ] [ ] [ ]g n f n h n G k F k H k
Zero-padded signals
36
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
1 2[ ] {1, 2, 2}, [ ] {1, 1}, 3, 2f n h n N N
[ ] {1, 2, 2, 0}, [ ] {1, 1, 0, 0}f n h n Zero-padding to length N=N1+N2-1 =4
4
4
4
4
[ ] 1 2 2 0 [ ]
[( 0) ] 0 0 1 1 0 0 1 1
[( 1) ] 0 0 1 1 0 0 1
[( 2) ] 0 0 1 1 0 0
[( 3) ] 0 0 1 1 2
f m g n
h n
h n
h n
h n
The result is the same as the linear convolution.
37
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
Verification using DFT
1 1 1 1 1 5
1 1 2 1 2
1 1 1 1 2 1
1 1 0 1 2
j j j
j j j
F = Af
1 1 1 1 1 0
1 1 1 1
1 1 1 1 0 2
1 1 0 1
j j j
j j j
H = Ah
38
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
Element-wise multiplication
[ ] [ ] [ ]G k F k H k
5 0 0
( 1 2) (1 ) 1 3
1 2 2
( 1 2) (1 ) 1 3
j j j
j j j
G = F H
39
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
Inverse DFT of the result
1 *
1 1 1 1 0 1
1 1 1 3 11
1 1 1 1 2 04
1 1 1 3 2
T j j j
j j j
g = A G = A
The same result as their linear convolution.
40
C. Nikou – Digital Image Processing (E12)
2D continuous signals
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
0 0 0 0( , ) ( ) ( )x x y y x x y y Separable:
0 0 0 0( , ) ( , ) ( , )f x y x x y y dydx f x y
0 0
0 0
, ,( , )
0 otherwise
x x y yx x y y
41
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
The 2D impulse train is also separable:
( , ) ( ) ( ) ( , )X Y X Y
n m
S x y S x S y x n X y n Y
42
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • The Fourier transform of a continuous 2D
signal f (x,y).
2 ( )( , ) ( , ) j x vyF f x y e dydx
2 ( )( , ) ( , ) j x vyf x y F e d d
43
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Example: FT of f (x,y)=δ(x)
2 ( )( , ) ( ) j x vyF x e dydx
2 2( ) j x j vyx e dx e dy
2j vye dy
( )
x
y f (x,y)=δ(x)
μ
ν F(μ,ν)=δ(ν)
44
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • Example: FT of f (x,y)=δ(x-y)
2 ( )( , ) ( ) j x vyF x y e dydx
2 2( ) j x j vyx y e dx e dy
2 2j y j ye e dy
( )
x
yf (x,y)=δ(x-y)
μ
ν F(μ,ν)=δ(μ+ν)
2 ( )j ye dy
45
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
2
/ 2, / 2
sin( ) sin( )( , ) ( , ) ( , )
( ) ( )W W
W Wf x y P x y F W
W W
46
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • 2D continuous convolution
( , )* ( , ) ( , ) ( , )f x y h x y F H
( , )* ( , ) ( , ) ( , )f x y h x y f x y h d d
• We will examine the discrete convolution
in more detail.
• Convolution property
47
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • 2D sampling is accomplished by
( , ) ( , )X Y
n m
S x y x n X y n Y
• The FT of the sampled 2D signal consists of
repetitions of the spectrum of the 1D
continuous signal.
1 1( , ) ,
n
m nF F
X Y X Y
48
C. Nikou – Digital Image Processing (E12)
2D continuous signals (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • The Nyquist theorem involves both the
horizontal and vertical frequencies.
max max
1 12 , 2v
X Y
Over-sampled Under-sampled
49
C. Nikou – Digital Image Processing (E12)
Aliasing
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
50
C. Nikou – Digital Image Processing (E12)
Aliasing
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
The difference is more pronounced in the area inside the bottle
51
C. Nikou – Digital Image Processing (E12)
Aliasing - Moiré Patterns
• Effect of sampling a scene with periodic or
nearly periodic components (e.g.
overlapping grids, TV raster lines and
stripped materials).
• In image processing the problem arises
when scanning media prints (e.g.
magazines, newspapers).
• The problem is more general than sampling
artifacts.
52
C. Nikou – Digital Image Processing (E12)
Aliasing - Moiré Patterns (cont.)
• Superimposed grid drawings (not digitized)
produce the effect of new frequencies not
existing in the original components.
53
C. Nikou – Digital Image Processing (E12)
Aliasing - Moiré Patterns (cont.)
• In the printing industry the problem
comes when scanning photographs from
the superposition of:
• The sampling lattice (usually horizontal and
vertical).
• Dot patterns on the newspaper image.
54
C. Nikou – Digital Image Processing (E12)
Aliasing - Moiré Patterns (cont.)
55
C. Nikou – Digital Image Processing (E12)
Aliasing - Moiré Patterns (cont.)
• The printing
industry uses
halftoning to
cope with the
problem.
• The dot size is
inversely
proportional to
image intensity.
56
C. Nikou – Digital Image Processing (E12)
2D discrete convolution
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
m
n3 2
f [m,n] m
n
1 1
1 -1
h [m,n]
[ , ] [ , ]* [ , ] [ , ] [ , ]k l
g m n f m n h m n f k l h m k n l
• Take the symmetric of one of the signals with
respect to the origin.
• Shift it and compute the sum at every position
[m,n].
57
C. Nikou – Digital Image Processing (E12)
2D discrete convolution (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
n
m3 2
f [m,n] n
m
1 1
1 -1
h [m,n]
l
k
h [1-k,1-l]
-1 1
1 1
3 2
l
k
h [-k,-l]
-1 1
1 1
3 2
g [0,0]=0 g [1,1]=0
58
C. Nikou – Digital Image Processing (E12)
2D discrete convolution (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
n
m3 2
f [m,n] n
m
1 1
1 -1
h [m,n]
l
k
h [3-k,2-l]
-1 1
1 1
3 2
l
k
h [2-k,2-l]-1 1
1 1
3 2
g [2,2]=3 g [3,2]=-1
59
C. Nikou – Digital Image Processing (E12)
2D discrete convolution (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
)
n
m3 2
f [m,n] n
m
1 1
1 -1
h [m,n]
n
m
g[m,n]3 5
3 -1
2
-3
M1+M2-1=3
N1+N2-1=2
60
C. Nikou – Digital Image Processing (E12)
The 2D DFT
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • 2D DFT pair of image f [m,n] of size MxN.
1 1 2
0 0
1 1 2
0 0
[ , ] [ , ]
1[ , ] [ , ]
km lnM N jM N
m n
km lnM N jM N
m n
F k l f m n e
f m n F k l eMN
0 1 0 1
0 1 0 1,
k M m M
l N n N
61
C. Nikou – Digital Image Processing (E12)
The 2D DFT (cont.)
Ima
ge
s ta
ke
n fro
m G
on
za
lez &
Wood
s, D
igita
l Im
age
Pro
ce
ssin
g (
20
02
) • All of the properties of 1D DFT hold.
• Particularly:
– Let f [m,n] be of size M1xN1 and h[m,n] of size
M2xN2 .
– If the signals are zero-padded to size (M1+M2-
1)x(N1+N2-1) then their circular convolution will
be the same as their linear convolution and:
[ , ] [ , ]* [ , ] [ , ] [ , ] [ , ]g m n f m n h m n G k l F k l H k l