Digital Image Processing
Download
Report
Transcript Digital Image Processing
Digital Image Processing
Filtering in the Frequency Domain
(Fundamentals)
Christophoros Nikou
[email protected]
University of Ioannina - Department of Computer Science
2
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
C. Nikou – Digital Image Processing (E12)
3
Jean Baptiste Joseph Fourier
Fourier was born in Auxerre,
France in 1768.
– Most famous for his work “La
Théorie Analitique 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.
C. Nikou – Digital Image Processing (E12)
The Big Idea
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
4
=
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
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
5
1D continuous signals
• It may be
considered both as
continuous and
discrete.
• Useful for the
representation of
discrete signals
through sampling
of continuous
signals.
x x0
,
( x x0 )
0 otherwise
f ( x) ( x x0 )dx f ( x0 )
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
6
Impulse train function
ST (t )
(t nT )
n
x[n] x(t )ST (t )
n
n
x(t ) (t nT ) x(nT ) (t nT )
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
7
x[n] x(t )ST (t )
x(t ) (t nT )
n
x(nT ) (t nT )
n
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
8
1D continuous signals (cont.)
• The Fourier series expansion of a periodic
signal f (t).
f (t )
ce
n
T /2
j
2
nt
T
n
1
cn
f
(
t
)
e
T T/ 2
j
2
nt
T
dt
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
9
1D continuous signals (cont.)
• The Fourier transform of a continuous
signal f (t).
F ( )
f (t )e
j 2t
dt
f (t )
F ( )e j 2t d
• Attention: the variable is the frequency (Hz) and
not the radial frequency (Ω=2πμ) as in the Signals
and Systems course.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
10
1D continuous signals (cont.)
sin(W )
f (t ) PW / 2 (t ) F ( ) W
(W )
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
11
1D continuous signals (cont.)
• 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 ( )
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
12
• Intermediate result
− The Fourier transform of the impulse train.
1
(t nT )
T
n
n
T
n
• It is also an impulse train in the frequency
domain.
• Impulses are equally spaced every 1/ΔΤ.
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
13
Sampling
x[n] x(t )ST (t )
x(t ) (t nT )
n
x(nT ) (t nT )
n
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
14
1D continuous signals (cont.)
• 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.
f (t ) F ( )
1
f (nT ) f [n] F ( )
T
n
F
T
n
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
15
1D continuous signals (cont.)
Nyquist theorem
1
2 max
T
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
16
1D continuous signals (cont.)
FT of a continuous signal
Oversampling
Critical sampling with
the Nyquist frequency
Undersampling
Aliasing appears
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
17
1D continuous signals (cont.)
• Reconstruction (under correct sampling).
F ( ) F ( ) H ( )
t
f (t ) f (t )* T sin c
T
C. Nikou – Digital Image Processing (E12)
1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
18
• Reconstruction
− Provided a correct sampling, the continuous
signal may be perfectly reconstructed by its
samples.
f (t )
n
(t nT )
f (nT ) sinc
n
T
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
19
1D continuous signals (cont.)
• Under aliasing, the
reconstruction of
the continuous
signal not correct.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
20
1D continuous signals (cont.)
Aliased signal
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
21
The Discrete Fourier Transform
• The Fourier transform of a sampled (discrete)
signal is a continuous function of the frequency.
1
F ( )
T
n
F
T
n
• For a N-length discrete signal, taking N samples of
its Fourier transform at frequencies:
k
k
, k 0,1,.., N 1
N T
provides the discrete Fourier transform (DFT) of
the signal.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
22
The Discrete Fourier Transform
(cont.)
• DFT pair of signal f [n] of length N.
N 1
F [k ] f [n]e
j
2 nk
N
0 k N 1
,
n 0
N 1
1
f [n] F [k ]e
N n 0
j
2 nk
N
,
0 n N 1
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
23
The Discrete Fourier Transform
(cont.)
• 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:
wN
n
e
2
j
N
n
n
wN e
C. Nikou – Digital Image Processing (E12)
j
2 n
N
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
24
The Discrete Fourier Transform
(cont.)
• Property: sum of complex exponentials
1 N kn 1, k rN , r
wN
otherwise
N n 0
0,
The proof is left as an exercise.
wN e
j
2
N
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
25
The Discrete Fourier Transform
(cont.)
• DFT pair of signal f [n] of length N may be
expressed in matrix-vector form.
N 1
F [k ] f [n]w ,
nk
N
n 0
1
f [ n]
N
wN e
j
N 1
0 k N 1
F[k ]w
n 0
nk
N
,
0 n N 1
2
N
C. Nikou – Digital Image Processing (E12)
26
The Discrete Fourier Transform
(cont.)
F = Af
w0 0
N
1 0
wN
A
wN 1 0
N
w
w
w
w
0 1
N
0 2
N
1 1
N
1 2
N
w w
N 1 1
N
N 1 2
N
w
w
1 N 1
N
N 1 N 1
wN
0
N
N 1
f = f [0], f [1],..., f [ N 1] , F = F [0], F [1],..., F [ N 1]
T
C. Nikou – Digital Image Processing (E12)
T
27
The Discrete Fourier Transform
(cont.)
Example for N=4
1 1 1 1
1 j 1 j
A
1 1 1 1
1 j 1 j
C. Nikou – Digital Image Processing (E12)
The Discrete Fourier Transform
(cont.)
28
The inverse DFT is then expressed by:
-1
f =A F
0
wN
1 0
1 w
N
N
N 1 0
wN
0
A 1
1
A
N
* T
w
w
0
N
1
1 1
N
w
w
0
N
2
1 2
N
w w
N 1 1
N
N 1 2
N
w
1 N 1
wN
N
1
wNN 1
0
N
N 1
This is derived by the complex exponential sum
property.
C. Nikou – Digital Image Processing (E12)
* T
Linear convolution
29
f [n] {1, 2, 2}, h[n] {1, 1}, N1 3, N2 2
g[n] f [n]* h[n]
f [m]h[n m]
m
is of length N=N1+N2-1=4
C. Nikou – Digital Image Processing (E12)
Linear convolution (cont.)
30
f [n] {1, 2, 2}, h[n] {1, 1}, N1 3, N2 2
g[n] f [n]* h[n]
f [m]h[n m]
m
f [ m]
n 0 h[0 m] 1
n 1 h [1 m]
n 2 h[2 m]
n 3 h [3 m]
1
2
2
1
1
1
1
1
1 1
0
2
1
1
g[ n]
g[n] {1, 1, 0, 2}
C. Nikou – Digital Image Processing (E12)
Circular shift
31
• 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
x[(n m) N ] x[(n m) mod N ]
• Example: x[n] is of length N=8.
x[(2) N ] x[(2)8 ] x[6]
x[(10)N ] x[(10)8 ] x[2]
C. Nikou – Digital Image Processing (E12)
Circular convolution
32
f [n] {1, 2, 2}, h[n] {1, 1}, N1 3, N2 2
g[n]=f [n]h[n]
m
f [m]h[(n m) N ]
Circular shift modulo N
The result is of length N max N1, N2 3
C. Nikou – Digital Image Processing (E12)
33
Circular convolution (cont.)
f [n] {1, 2, 2}, h[n] {1, 1}, N1 3, N2 2
g[n]=f [n]h[n]
m
f [m]h[(n m) N ]
f [ m]
1 2 2 g[ n]
n 0 h [(0 m) N ] 1 1
1
1
n 1 h [(1 m) N ]
1 1
1
n 2 h [(2 m) N ]
1 1
0
g[n] { 1, 1, 0,}
C. Nikou – Digital Image Processing (E12)
34
DFT and convolution
g[n]=f [n]h[n] G[k ] F[k ]H [k ]
• 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?
C. Nikou – Digital Image Processing (E12)
35
DFT and convolution (cont.)
g[n]=f [n]h[n] G[k ] F[k ]H [k ]
• 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
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
36
f [n] {1, 2, 2}, h[n] {1, 1}, N1 3, N2 2
Zero-padding to length N=N1+N2-1 =4
f [n] {1, 2, 2, 0}, h[n] {1, 1, 0, 0}
f [ m]
h[(n 0) 4 ] 0 0 1
h[(n 1) 4 ]
h[(n 2) 4 ]
h[(n 3) 4 ]
0
1
1
2
0
0 1 1
0 0 1
0
2 0 g[ n]
0 1
1
0
1
0
0
1
0
0 1
1
2
The result is the same as the linear convolution.
C. Nikou – Digital Image Processing (E12)
37
DFT and convolution (cont.)
Verification using DFT
1 1 1 1 1 5
1 j 1 j 2 1 j 2
F = Af
1 1 1 1 2 1
1 j 1 j 0 1 j 2
1 1 1 1 1 0
1 j 1 j 1 1 j
H = Ah
1 1 1 1 0 2
1 j 1 j 0 1 j
C. Nikou – Digital Image Processing (E12)
38
DFT and convolution (cont.)
G[k ] F[k ] H[k ]
Element-wise multiplication
(1
G = FH
(1
5 0
0
j 2) (1 j ) 1 j3
2
1 2
j 2) (1 j ) 1 j3
C. Nikou – Digital Image Processing (E12)
DFT and convolution (cont.)
39
Inverse DFT of the result
1 * T
g = A G = A
4
1
1 1 1 1 0 1
1 j 1 j 1 j3 1
1 1 1 1 2 0
1 j 1 j 1 j3 2
The same result as their linear convolution.
C. Nikou – Digital Image Processing (E12)
2D continuous signals
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
40
, x x0 , y y0
( x x0 , y y0 )
otherwise
0
f ( x, y) ( x x0 , y y0 )dydx f ( x0 , y0 )
Separable: ( x x0 , y y0 ) ( x x0 ) ( y y0 )
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
41
2D continuous signals (cont.)
The 2D impulse train is also separable:
SX Y ( x, y) SX ( x) SY ( y)
( x nX , y nY )
n m
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
42
2D continuous signals (cont.)
• The Fourier transform of a continuous 2D
signal f (x,y).
F ( , )
f ( x, y)e
j 2 ( x vy )
dydx
f ( x, y)
F (, )e
j 2 ( x vy )
C. Nikou – Digital Image Processing (E12)
d d
2D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
43
• Example: FT of f (x,y)=δ(x)
F ( , )
y
f (x,y)=δ(x)
j 2 ( x vy )
(
x
)
e
dydx
x
j 2 x
j 2 vy
(
x
)
e
dx
e
dy
e
j 2 vy
dy ( )
C. Nikou – Digital Image Processing (E12)
ν
F(μ,ν)=δ(ν)
μ
2D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
44
• Example: FT of f (x,y)=δ(x-y)
F ( , )
f (x,y)=δ(x-y)
y
j 2 ( x vy )
(
x
y
)
e
dydx
x
j 2 vy
j 2 x
( x y )e
dx e
dy
e
ν
F(μ,ν)=δ(μ+ν)
j 2 y j 2 y
e
dy
j 2 ( ) y
e
dy
( )
C. Nikou – Digital Image Processing (E12)
μ
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
45
2D continuous signals (cont.)
sin(W ) sin( W )
f ( x, y) PW / 2,W / 2 ( x, y) F ( , ) W
(W ) ( W )
2
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
46
2D continuous signals (cont.)
• 2D continuous convolution
f ( x, y)* h( x, y)
f ( x , y )h( , )d d
• We will examine the discrete convolution
in more detail.
• Convolution property
f ( x, y)* h( x, y) F ( , ) H ( , )
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
47
2D continuous signals (cont.)
• 2D sampling is accomplished by
SX Y ( x, y )
( x nX , y nY )
n m
• The FT of the sampled 2D signal consists of
repetitions of the spectrum of the 1D
continuous signal.
1 1
F ( , )
X Y
m
n
F
,
X
Y
n
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
48
2D continuous signals (cont.)
• The Nyquist theorem involves both the
horizontal and vertical frequencies.
1
1
2 max ,
2vmax
X
Y
Over-sampled
Under-sampled
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
49
Aliasing
C. Nikou – Digital Image Processing (E12)
50
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.
C. Nikou – Digital Image Processing (E12)
51
Aliasing - Moiré Patterns (cont.)
• Superimposed grid drawings (not digitized)
produce the effect of new frequencies not
existing in the original components.
C. Nikou – Digital Image Processing (E12)
52
Aliasing - Moiré Patterns (cont.)
• In 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.
C. Nikou – Digital Image Processing (E12)
53
Aliasing - Moiré Patterns (cont.)
C. Nikou – Digital Image Processing (E12)
54
Aliasing - Moiré Patterns (cont.)
• The printing
industry uses
halftoning to
cope with the
problem.
• The dot size is
inversely
proportional to
image intensity.
C. Nikou – Digital Image Processing (E12)
2D discrete convolution
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
55
m
m
f [m,n]
3 2
h [m,n]
1 1
1 -1
n
g[m, n] f [m, n]* h[m, n]
n
f [k , l ]h[m k , n l ]
k 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].
C. Nikou – Digital Image Processing (E12)
2D discrete convolution (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
56
n
n
f [m,n]
3 2
h [m,n]
1 1
1 -1
m
l
h [-k,-l]
l
g [0,0]=0
3 2
-1 1
1 1
m
k
h [1-k,1-l]
g [1,1]=0
3 2
-1 1
1 1
C. Nikou – Digital Image Processing (E12)
k
2D discrete convolution (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
57
n
n
f [m,n]
3 2
h [m,n]
1 1
1 -1
m
m
l
l
g [2,2]=3
h [2-k,2-l]
-1 13 2
1 1
h [3-k,2-l]
k
C. Nikou – Digital Image Processing (E12)
g [3,2]=-1
3 21
-1
1 1
k
2D discrete convolution (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
58
n
n
f [m,n]
3 2
h [m,n]
1 1
1 -1
m
n
3 5 2
3 -1 -3
g[m,n]
m
M1+M2-1=3
N1+N2-1=2
C. Nikou – Digital Image Processing (E12)
m
The 2D DFT
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
59
• 2D DFT pair of image f [m,n] of size MxN.
M 1 N 1
F [k , l ] f [m, n]e
km ln
j 2
M N
m0 n 0
1
f [ m, n ]
MN
M 1 N 1
F [k , l ]e
km ln
j 2
M
N
m 0 n 0
0 k M 1
,
0 l N 1
0 m M 1
0 n N 1
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
60
The 2D DFT (cont.)
• 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+M21)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 ]
C. Nikou – Digital Image Processing (E12)