You are on page 1of 60

Digital Image Processing

Filtering in the Frequency Domain


(Fundamentals)

Christophoros Nikou
cnikou@cs.uoi.gr

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)
4 The Big Idea
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

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)
5 1D continuous signals

• It may be
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

considered both as
continuous and
discrete.
• Useful for the
representation of , x  x0
discrete signals  ( x  x0 )  
 0 otherwise
through sampling

of continuous
signals.


f ( x) ( x  x0 )dx  f ( x0 )

C. Nikou – Digital Image Processing (E12)


6 1D continuous signals (cont.)

Impulse train function


Images taken from Gonzalez & Woods, Digital Image Processing (2002)


ST (t )    (t  nT )
n 

 
x[n]  x(t ) S T (t )   x(t ) (t  nT )   x(nT ) (t  nT )
n  n 

C. Nikou – Digital Image Processing (E12)


7 1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

x[n]  x(t ) ST (t )


  x(t ) (t  nT )
n 


  x(nT ) (t  nT )
n 

C. Nikou – Digital Image Processing (E12)


8 1D continuous signals (cont.)

• The Fourier series expansion of a periodic


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

signal f (t).
 2

ce
j nt
f (t )  n
T

n 

T /2 2
1 j nt
cn  
T T / 2
f (t )e T
dt

C. Nikou – Digital Image Processing (E12)


9 1D continuous signals (cont.)

• The Fourier transform of a continuous


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

signal f (t).

F ( )  
 j 2 t
f (t )e dt



 F (  )e d
j 2t
f (t ) 

• 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)
10 1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

sin(W )
f (t )  PW / 2 (t )  F (  )  W
(W )
C. Nikou – Digital Image Processing (E12)
11 1D continuous signals (cont.)

• Convolution property of the FT.


Images taken from Gonzalez & Woods, Digital Image Processing (2002)


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)


12 1D continuous signals (cont.)

• Intermediate result
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

− The Fourier transform of the impulse train.


 
1  n 

n 
 (t  nT ) 
T
   
n  

T 

• It is also an impulse train in the frequency


domain.
• Impulses are equally spaced every 1/ΔΤ.

C. Nikou – Digital Image Processing (E12)


13 1D continuous signals (cont.)
Sampling
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

x[n]  x(t ) ST (t )


  x(t ) (t  nT )
n 


  x(nT ) (t  nT )
n 

C. Nikou – Digital Image Processing (E12)


14 1D continuous signals (cont.)

• Sampling
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

− 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  n 
f (nT )  f [n]  F (  ) 
T

n 
F  


T 

C. Nikou – Digital Image Processing (E12)


15 1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

Nyquist theorem
1
 2  max
T

C. Nikou – Digital Image Processing (E12)


16 1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

FT of a continuous signal

Oversampling

Critical sampling with


the Nyquist frequency

Undersampling
Aliasing appears
C. Nikou – Digital Image Processing (E12)
17 1D continuous signals (cont.)

• Reconstruction (under correct sampling).


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

F ( )  F ( ) H ( )

 t 
f (t )  f (t ) * T sin c  
 T 
C. Nikou – Digital Image Processing (E12)
18 1D continuous signals (cont.)

• Reconstruction
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

− Provided a correct sampling, the continuous


signal may be perfectly reconstructed by its
samples.


 (t  nT ) 
f (t )  
n 
f (nT ) sinc 
 n T 

C. Nikou – Digital Image Processing (E12)


19 1D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

• Under aliasing, the


reconstruction of
the continuous
signal not correct.

C. Nikou – Digital Image Processing (E12)


20 1D continuous signals (cont.)

Aliased signal
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

C. Nikou – Digital Image Processing (E12)


21 The Discrete Fourier Transform

• The Fourier transform of a sampled (discrete)


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

signal is a continuous function of the frequency.



1  n 
F ( ) 
T

n 
F  


T 
• 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)
22
The Discrete Fourier Transform
(cont.)
• DFT pair of signal f [n] of length N.
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

N 1 2 nk
j
F [k ]   f [n]e N
, 0  k  N 1
n 0
N 1 2 nk
1
 F[k ]e
j
f [ n]  N
, 0  n  N 1
N n 0

C. Nikou – Digital Image Processing (E12)


23
The Discrete Fourier Transform
(cont.)
• Property
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

– 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 n 2 n
 j  j
 wN   e  
n n

N N
wN e
 
C. Nikou – Digital Image Processing (E12)
24
The Discrete Fourier Transform
(cont.)
• Property: sum of complex exponentials
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

1 N kn 1, k  rN , r 
 wN  
N n 0 0, otherwise

The proof is left as an exercise.

2
j
wN  e N

C. Nikou – Digital Image Processing (E12)


25
The Discrete Fourier Transform
(cont.)
• DFT pair of signal f [n] of length N may be
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

expressed in matrix-vector form.


N 1
F [k ]   f [n]w , nk
N 0  k  N 1
n 0

1 N 1
f [n]   F [k ]wN ,
 nk
0  n  N 1
N n 0
2
j
wN  e N

C. Nikou – Digital Image Processing (E12)


26
The Discrete Fourier Transform
(cont.)
F = Af
  w0  0 w  0 1
w  0 2
w 
0 N 1

 N N N N

 1 0 1 N 1 
 wN  w  1 1
w  w 
1 2

A  N N N 
 
 
 w N 1 0 w  w 
N 1 1 N 1 2
 wN  
N 1 N 1 
 N N N

f =  f [0], f [1],..., f [ N  1] , F =  F [0], F [1],..., F [ N  1]


T T

C. Nikou – Digital Image Processing (E12)


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)


28
The Discrete Fourier Transform
(cont.)
The inverse DFT is then expressed by:
f = A -1F
* T
 0 
   wN  w  w   w  
0 0 1 0 2 0 N 1
N N N 
 1 0 1 N 1 

1  w  w 1 1
w   wN  
2

1
A 1 
1
N
 A 
* T
  N
N 
N N
 
  
  N 1 0 
  wN  w  w   wNN 1  
N 1 1 N 1 2 N 1

 N N

This is derived by the complex exponential sum


property.
C. Nikou – Digital Image Processing (E12)
29 Linear convolution

f [n]  {1, 2, 2}, h[n]  {1,  1}, N1  3, N 2  2


g[n]  f [n]* h[n]  
m 
f [m]h[n  m]

is of length N=N1+N2-1=4

C. Nikou – Digital Image Processing (E12)


30 Linear convolution (cont.)
f [n]  {1, 2, 2}, h[n]  {1,  1}, N1  3, N 2  2

g[n]  f [n]* h[n]  
m 
f [m]h[n  m]

f [ m] 1 2 2 g[ n]
n0 h[0  m] 1 1  1
n 1 h [1  m] 1 1  1
n2 h[2  m] 1 1  0
n3 h [3  m] 1 1  2
g[n]  {1, 1, 0,  2}
C. Nikou – Digital Image Processing (E12)
31 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
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)
32 Circular convolution

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, N 2  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)
36 DFT and convolution (cont.)
f [n]  {1, 2, 2}, h[n]  {1,  1}, N1  3, N 2  2

Zero-padding to length N=N1+N2-1 =4


f [n]  {1, 2, 2, 0}, h[n]  {1,  1, 0, 0}

f [ m] 1 2 2 0 g[ n]
h[(n  0)4 ] 0 0 1 1 0 0 1 1
h[(n  1) 4 ] 0 0 1 1 0 0 1
h[(n  2) 4 ] 0 0 1 1 0 0
h[(n  3)4 ] 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

 5 0   0 
(1  j 2)  (1  j )  1  j 3
G = FH   
 1 2   2 
   
(1  j 2)  (1  j )  1  j3

C. Nikou – Digital Image Processing (E12)


39 DFT and convolution (cont.)

Inverse DFT of the result

1 1 1 1   0   1
1 j 1  j  1  j 3  1
g = A G = A 
1 1 * T    
4 1 1 1 1  2   0
    
1  j 1 j  1  j 3  2

The same result as their linear convolution.

C. Nikou – Digital Image Processing (E12)


40 2D continuous signals

, x  x0 , y  y0
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

 ( x  x0 , y  y0 )  
 0 otherwise

 


 
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)
41 2D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

The 2D impulse train is also separable:


 
S X Y ( x, y )  S X ( x) S Y ( y )     ( x  nX , y  nY )
n  m 

C. Nikou – Digital Image Processing (E12)


42 2D continuous signals (cont.)

• The Fourier transform of a continuous 2D


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

signal f (x,y).
 
F (  , )  
 j 2 (  x  vy )
f ( x, y )e dydx
 

 

  F ( , )e d d 
j 2 (  x  vy )
f ( x, y ) 
 

C. Nikou – Digital Image Processing (E12)


43 2D continuous signals (cont.)
• Example: FT of f (x,y)=δ(x)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

y f (x,y)=δ(x)
 
F (  , )      j 2 (  x  vy )
( x ) e dydx x
 

 

  
 j 2 x  j 2 vy
 ( x ) e dx e dy
  ν F(μ,ν)=δ(ν)



e
 j 2 vy
 dy   ( ) μ



C. Nikou – Digital Image Processing (E12)


44 2D continuous signals (cont.)
• Example: FT of f (x,y)=δ(x-y) f (x,y)=δ(x-y)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

y
 
F (  , )      j 2 (  x  vy )
( x  y ) e dydx x
 


    j 2 vy
     ( x  y)e  j 2 x
dx e dy
    ν F(μ,ν)=δ(μ+ν)

 


 j 2 (   ) y
 e
 j 2 y  j 2 y
e dy  e dy μ
 

  (   )
C. Nikou – Digital Image Processing (E12)
45 2D continuous signals (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

sin(W ) sin( W )
f ( x, y)   PW / 2,W / 2 ( x, y)  F (  , )  W 2

(W ) ( W )
C. Nikou – Digital Image Processing (E12)
46 2D continuous signals (cont.)

• 2D continuous convolution
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

 
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)
47 2D continuous signals (cont.)

• 2D sampling is accomplished by
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

 
SX Y ( x, y )     ( x  nX , y  nY )
n  m 

• The FT of the sampled 2D signal consists of


repetitions of the spectrum of the 1D
continuous signal.

1 1  m n 
F (  , ) 
X Y

n 
F  
 X
,  
Y 

C. Nikou – Digital Image Processing (E12)


48 2D continuous signals (cont.)

• The Nyquist theorem involves both the


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

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

C. Nikou – Digital Image Processing (E12)


Aliasing
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)


55 2D discrete convolution
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

m f [m,n] m h [m,n]
1 1
3 2 1 -1 n
n
 
g[m, n]  f [m, n]* h[m, 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)
56 2D discrete convolution (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

n f [m,n] n h [m,n]
1 1
3 2 1 -1 m
m

l l
g [0,0]=0 g [1,1]=0
h [-k,-l] h [1-k,1-l]
3 2 3 2
k -1 1 k
-1 1
1 1
1 1
C. Nikou – Digital Image Processing (E12)
57 2D discrete convolution (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

n f [m,n] n h [m,n]
1 1
3 2 1 -1 m
m

l l
g [2,2]=3 g [3,2]=-1
h [2-k,2-l] h [3-k,2-l]
-1 13 2 k
3 21
-1 k
1 1 1 1

C. Nikou – Digital Image Processing (E12)


58 2D discrete convolution (cont.)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)

n f [m,n] n h [m,n]
1 1
3 2 1 -1 m
m

n g[m,n]
3 5 2
3 -1 -3
m
M1+M2-1=3
N1+N2-1=2
C. Nikou – Digital Image Processing (E12)
59 The 2D DFT

• 2D DFT pair of image f [m,n] of size MxN.


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

M 1 N 1  km ln 
 j 2   
F [k , l ]    f [m, n]e M N

m0 n 0

M 1 N 1  km ln 
1 j 2   
f [m, n] 
MN
  F[k , l ]e
m0 n 0
M N

0  k  M  1 0  m  M  1
 , 
 0  l  N 1  0  n  N 1
C. Nikou – Digital Image Processing (E12)
60 The 2D DFT (cont.)

• All of the properties of 1D DFT hold.


Images taken from Gonzalez & Woods, Digital Image Processing (2002)

• 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 ]

C. Nikou – Digital Image Processing (E12)

You might also like