Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 85

Digital Image Processing

Filtering in the Frequency Domain

1
The Discrete Fourier Transform (DFT) of One
Variable

M 1
F (  )   f ( x)e  j 2 x / M ,  0,1,..., M  1
x 0

M 1
1
f ( x) 
M
 F
 0
(  ) e j 2 x / M
, x  0,1, 2,..., M  1

11/17/2023 2
2-D Impulse and Sifting Property: Continuous
 if t  z  0
The impulse  (t , z ),  (t , z )  
0 otherwise
 
and    
 (t , z ) dtdz  1

The sifting property


 
 
 
f (t , z ) (t , z )dtdz  f (0, 0)
and
 
 
 
f (t , z ) (t  t0 , z  z0 )dtdz  f (t0 , z0 )

11/17/2023 3
2-D Impulse and Shifting Property: Discrete

1 if x  y  0
The impulse  ( x, y ),  ( x, y)  
0 otherwise

The shifting property


 


x  y 
f ( x, y ) ( x, y )  f (0, 0)

and
 


x  y 
f ( x, y ) ( x  x0 , y  y0 )  f ( x0 , y0 )

11/17/2023 4
2-D Fourier Transform: Continuous

 
F (  , )    f (t , z ) e  j 2 (  t  z )
dtdz
 

and
 
f (t , z )    f (  , )e j 2 (  t  z )
d  d
 

11/17/2023 5
2-D Fourier Transform: Continuous
 
F (  , )    f (t , z )e j 2 ( t  z ) dtdz
 
T /2 Z /2
  Ae  j 2 ( t  z ) dtdz
T /2  Z /2

 sin(T )   sin( T ) 
 ATZ     T 
  T  

11/17/2023 6
2-D Sampling and 2-D Sampling Theorem

2  D impulse train:
 
sT Z (t , z )     (t  mT , z  nZ )
m  n 

11/17/2023 7
2-D Sampling and 2-D Sampling Theorem

Function f (t , z ) is said to be band-limited if its Fourier transform


is 0 outside a rectangle established by the intervals [-max ,max ]
and [- max , max ], that is
F (  , )  0 for |  | max and |  |  max

Two-dimensional sampling theorem:


A continuous, band-limited function f (t , z) can be recovered with
no error from a set of its samples if the sampling intervals are
1 1
T< and Z<
2 max 2 max
11/17/2023 8
2-D Sampling and 2-D Sampling Theorem

11/17/2023 9
Aliasing in Images: Example
In an image system, the
number of samples is fixed at
96x96 pixels. If we use this
system to digitize checkerboard
patterns …

Under-sampling

11/17/2023 10
Aliasing in Images: Example

Re-sampling

11/17/2023 11
Aliasing in Images: Example

Re-sampling

11/17/2023 12
2-D Discrete Fourier Transform and Its
Inverse
DFT:
M 1 N 1  j 2 (  x / M  y / N )

F (  , )    f ( x, y )e
x 0 y 0

  0,1, 2,..., M  1;  0,1, 2,..., N  1;


f ( x, y ) is a digital image of size M  N.

IDFT:
M 1 N 1 j 2 (  x / M  y / N )
1
f ( x, y ) 
MN
  F ( , )e
x 0 y 0

11/17/2023 13
Properties of the 2-D DFT
relationships between spatial and frequency intervals

Let T and Z denote the separations between samples,


then the seperations between the corresponding discrete,
frequency domain variables are given by
1
 
M T
1
and  
N Z

11/17/2023 14
Properties of the 2-D DFT
translation and rotation

f ( x, y )e j 2 ( 0 x / M  0 y / N )  F (   0 ,  0 )
and
 j 2 (  x0 / M  y0 / N )
f ( x - x0 , y - y0 )  F (  , )e

Using the polar coordinates


x  r cos  y=rsin  = cos  = sin 
results in the following transform pair:
f (r ,   0 )  F ( ,   0 )
11/17/2023 15
Properties of the 2-D DFT
periodicity

2  D Fourier transform and its inverse are infinitely periodic


F (  , )  F (   k1M , )  F (  ,  k 2 N )  F (   k1M ,  k 2 N )

f ( x, y )  f ( x  k1M , y )  f ( x, y  k2 N )  f ( x  k1M , y  k2 N )

f ( x ) e j 2 (  0 x / M )  F (    0 )
0  M / 2, f ( x)( 1) x  F (   M / 2)

f ( x, y )( 1) x y
 F (   M / 2,  N / 2)

11/17/2023 16
Properties of the 2-D DFT
Symmetry

11/17/2023 17
Properties of the 2-D DFT
Fourier Spectrum and Phase Angle

2-D DFT in polar form


F (u , v) | F (u, v) | e j (u ,v )
Fourier spectrum
1/2
| F (u , v) |  R (u, v)  I (u, v) 
2 2

Power spectrum
P (u , v) | F (u, v) |2  R 2 (u, v)  I 2 (u , v)
Phase angle
 I (u, v) 
 (u,v)=arctan  
 R (u , v ) 

11/17/2023 18
11/17/2023 19
11/17/2023 20
Example: Phase Angles

11/17/2023 21
Example: Phase Angles and The Reconstruction

Phase angle is crucial !!!

11/17/2023 22
2-D Convolution Theorem
1-D convolution
M 1
f ( x ) h( x )   f ( m)h( x  m)
m 0

2-D convolution
M 1 N 1
f ( x, y ) h ( x, y )    f (m, n)h( x  m, y  n)
m 0 n 0

x  0,1, 2,..., M  1; y  0,1, 2,..., N  1.


f ( x , y ) h ( x , y )  F (u, v ) H (u, v )
f ( x , y )h ( x , y )  F (u, v ) H (u, v )
11/17/2023 23
Summary

11/17/2023 24
Summary

11/17/2023 25
Summary

11/17/2023 26
Summary

11/17/2023 27
The Basic Filtering in the Frequency Domain

Why is the spectrum at


almost ±45 degree stronger
than the spectrum at other
directions?

11/17/2023 28
Histogram Processing Vs Frequency
domain Analysis of Image
► Both are fundamentally different
Histogram- plots the no. of repetitions of each intensity value from the
spatial domain (statistical info)
Spectrum- Plots the magnitude of a complex quantity F(u,v) obtained
after transforming the image through Fourier Transform
► Histogram Processing gives us the pixel density or loosely speaking
probability density of each pixel and relates to the brightness/contrast of
the image

► However, Frequency analysis gives us the rate of change of intensity


values (frequency), means if you want to deal with slowly varying (low
frequency) and fast varying (high frequency) intensities, frequency 29
analysis helps
11/17/2023
The Basic Filtering in the Frequency Domain

► Modifying the Fourier transform of an image to achieve a


specific objective

► Computing the inverse transform to obtain the processed


result
g ( x, y )  1{H (u, v) F (u, v)}

F (u , v) is the DFT of the input image


H (u , v) is a filter function.
where G (u , v)  H (u , v) F (u , v)
11/17/2023 or g ( x, y )  h( x, y )  f ( x, y ) 30
The Effect of Basic Filtering in the Frequency
Domain
► In a filter H(u,v) that is 0 at the center of the transform
and 1 elsewhere, what’s the output image?
A notch filter: Flat with a
hole/notch present at cetre

The filter is making average intensity values of the image (dc value) zero resulting
into a blackish image while keeping the edges intact (having higher intensity values)
11/17/2023 31
The Basic Filtering in the Frequency Domain

Non-zero
spectrum

11/17/2023 32
Effect of Filtering on the Phase of the
Image: Zero-Phase-Shift Filters
1
g ( x, y )   {H (u , v) F (u , v)}
F (u , v)  R (u , v)  jI (u , v )
1
g ( x, y )    H (u, v) R(u, v)  jH (u, v) I (u, v)
Filters affect the real and imaginary parts equally,
and thus no effect on the phase.
These filters are called zero-phase-shift filters

11/17/2023 33
Examples: Nonzero-Phase-Shift Filters

Even small
Phasechanges
angle is in the phase angle can ishave
Phase angle
dramaticmultiplied
(usually by undesirable) effects on the
multiplied by filtered
output 0.5 0.25

11/17/2023 34
The Effect of Zero-padding in Basic Filtering in
the Frequency Domain

Observations: Blurring is not uniform in (b) but uniform in (c)

Reason?
11/17/2023 Zero padding->Circular convolution->DFT?? 35

(Wraparound error)
Summary:
Steps for Filtering in the Frequency Domain
1. Given an input image f(x,y) of size MxN, obtain the
padding parameters P and Q. Typically, P = 2M and Q = 2N.

2. Form a padded image, fp(x,y) of size PxQ by


appending the necessary number of zeros to f(x,y)

3. Multiply fp(x,y) by (-1)x+y to center its transform

4. Compute the DFT, F(u,v) of the image from step 3

5. Generate a real, symmetric filter function*, H(u,v), of


size PxQ with center at coordinates (P/2, Q/2)
*generate from a given spatial filter, we pad the spatial filter, multiply the expanded
array by (-1)x+y, and compute the DFT of the result to obtain a centered H(u,v).
11/17/2023 36
Summary:
Steps for Filtering in the Frequency Domain
6. Form the product G(u,v) = H(u,v)F(u,v) using array
multiplication

7. Obtain the processed image

 
g p ( x, y )  real  1 G (u, v)  ( 1) x  y

8. Obtain the final processed result, g(x,y), by extracting


the MxN region from the top, left quadrant of g p(x,y)

11/17/2023 37
An Example:
Steps for Filtering in the Frequency Domain

11/17/2023 38
Correspondence Between Filtering in the
Spatial and Frequency Domains (1)

Let H(u) denote the 1-D frequency domain Gaussian filter


- u 2 /2 2
H (u)  Ae

The corresponding filter in the spatial domain


2 2 2 x 2
h( x)  2 Ae

1. Both components are Gaussian and real


2. The functions behave reciprocally, means opposite
characteristics, one is wider other will be narrower and
11/17/2023 vice-versa 39
Correspondence Between Filtering in the
Spatial and Frequency Domains (2)
Let H (u ) denote the difference of Gaussian filter
- u 2 /212 - u 2 /2 22
H (u )  Ae  Be
with A  B and  1   2

The corresponding filter in the spatial domain


2 212 x 2 2 2  22 x2
h( x)  2 1 Ae  2 2 Ae

DoG is a High-pass filter or low-pass filter OR?

11/17/2023 40
Correspondence Between Filtering in the
Spatial and Frequency Domains (3)

The masks shown are the standard 2D masks used for LPF and HPF of images
11/17/2023 41 in
spatial domain. They are generated by sampling the Gaussian curve
Correspondence Between Filtering in the
Spatial and Frequency Domains: Example

600x600

11/17/2023 42
Correspondence Between Filtering in the
Spatial and Frequency Domains: Example
H(x,y)

H(u,v)

11/17/2023 43
Generate H(u,v) from h(x,y)

 f ( x, y ) 0  x  599 and 0  y  599


f p ( x, y )  
 0 600  x  602 or 600  y  602

 h ( x, y ) 0  x  2 and 0  y  2
h p ( x, y )  
0 3  x  602 or 3  y  602

Here P  A(600)  C (3)  1  602;


Q  B(600)  D(3)  1  602.

11/17/2023 44
Image Smoothing Using Frequency Domain Filters

• Ideal LPF
• Butterworth LPF
• Gaussian LPF

Image Sharpening Using Frequency Domain Filters

• Ideal HPF
• Butterworth HPF
• Gaussian HPF

11/17/2023 45
Image Smoothing Using Filter Domain Filters:
Ideal LPF

Ideal Lowpass Filters (ILPF)


1 if D(u, v)  D0
H (u , v )  
0 if D(u, v)  D0

D0 is a positive constant and D(u, v) is the distance between a point (u , v)


in the frequency domain and the center of the frequency rectangle
2 1/2
D(u, v)  (u  P / 2)  (v  Q / 2) 
2

11/17/2023 46
Image Smoothing Using Frequency Domain
Filters: ILPF

11/17/2023 47
ILPF
Filtering
Example
with
different
cut-off
frequencies

11/17/2023 48
The Spatial Representation of ILPF

Observation-Ringing effect in the intensity image and the corresponding side lobes in Sinc
function. It arises due to sharp transition in frequency domain and the corresponding side
lobes in spatial domain
11/17/2023 49
Image Smoothing Using Frequency Domain
Filters: BLPF
Butterworth Lowpass Filters (BLPF) of order n and
with cutoff frequency D0
1
H (u , v ) 
1   D(u , v) / D0 
2n

11/17/2023 50
Observation- Sharp and smooth transition in case of ILPF and BLPF

11/17/2023 51
The Spatial Representation of BLPF

11/17/2023
Observation-Ringing effect as order increases. Side lobes of the Sinc 52
function responsible for generating ringing effect
Image Smoothing Using Frequency Domain
Filters: GLPF

Gaussian Lowpass Filters (GLPF) in two dimensions is given


 D 2 ( u ,v )/2 2
H (u , v )  e

By letting   D0
 D 2 ( u ,v )/2 D0 2
H (u , v )  e

As in both spatial and frequency domain, representation remains Gaussian


only, no ringing effect in GLPF
11/17/2023 53
Image Smoothing Using Frequency Domain
Filters: GLPF

11/17/2023 54
11/17/2023 55
Examples of smoothing by GLPF (1)

11/17/2023 56
Examples of smoothing by GLPF (2)

11/17/2023 57
Image Smoothing Using Frequency Domain Filters

• Ideal LPF
• Butterworth LPF
• Gaussian LPF

Image Sharpening Using Frequency Domain Filters

• Ideal LPF
• Butterworth LPF
• Gaussian LPF

11/17/2023 58
Image Sharpening Using Frequency Domain
Filters

A highpass filter is obtained from a given lowpass filter


using

H HP (u , v)  1  H LP (u, v)

A 2-D ideal highpass filter (IHPL) is defined as


0 if D(u , v)  D0
H (u , v)  
1 if D(u , v)  D0

11/17/2023 59
Image Sharpening Using Frequency Domain
Filters

A 2-D Butterworth highpass filter (BHPL) is defined as


1
H (u , v) 
1   D0 / D(u , v) 
2n

A 2-D Gaussian highpass filter (GHPL) is defined as


 D 2 ( u ,v )/2 D02
H (u , v)  1  e

11/17/2023 60
11/17/2023 61
The Spatial Representation of Highpass Filters

Observation-Ringing effect in the intensity image and the corresponding side lobes in
Sinc function.
No ringing effect in Butterworth filter at lower order but present at higher order as it
tends to ideal HPF when order increases
11/17/2023 62

No ringing effect at all in Gaussian HPF


Filtering Results by IHPF

Ringing
effect

11/17/2023 63
Filtering Results by BHPF

11/17/2023 64
Filtering Results by GHPF

11/17/2023 65
Using Highpass Filtering and Threshold for
Image Enhancement

BHPF
(order 4 with a cutoff
frequency 50)

11/17/2023 66
The Laplacian in the Frequency Domain

H (u , v)  4 2 (u 2  v 2 ) After taking FT of  2 f ( x, y )

H (u , v)  4 2  (u  P / 2)2  (v  Q / 2)2 ) 


 4 2 D 2 (u , v)
The Laplacian image
 2 f ( x, y )  1 H (u , v) F (u , v)

Enhancement is obtained
g ( x, y )  f ( x, y )  c 2 f ( x, y ) c  -1
11/17/2023 67
The Laplacian in the Frequency Domain

The enhanced image


1
g ( x, y )   F (u, v)  H (u, v) F (u, v)
 1 1  H (u , v) F (u , v)

 
 1 1  4 2 D 2 (u , v)  F (u , v)

11/17/2023 68
The Laplacian in the Frequency Domain

11/17/2023 69
Unsharp Masking, Highboost Filtering and
High-Frequency-Emphasis Fitering
Unsharp masking
fUM ( x, y )  f ( x, y )  f LP ( x, y )

f LP ( x, y )  1  H LP (u , v) F (u , v) 

highboost filtering
f hb ( x, y )  Af ( x, y )  f LP ( x, y )
=( A  1) f ( x, y )  f HP ( x, y )

H hb (u , v)  ( A  1)  H HP (u, v)
11/17/2023 f hb ( x, y )  1  H hb (u , v) F (u , v)  70
Gaussian Filter
D0=40

High-Frequency-Emphasis Filtering
Gaussian Filter
K1=0.5, k2=0.75

11/17/2023 71
Homomorphic Filtering

f ( x , y )  i ( x, y ) r ( x , y )
  f ( x, y )  
=  i ( x, y )   r ( x, y )  ?

z ( x, y )  ln f ( x, y )  ln i ( x, y )  ln r ( x, y )

z ( x, y )  ln f ( x, y )  ln i ( x, y )   ln r ( x, y )

Z (u , v)  Fi (u , v)  Fr (u , v)

11/17/2023 72
Homomorphic Filtering

S (u , v)  H (u, v) Z (u , v)
 H (u, v) Fi (u, v)  H (u, v) Fr (u, v)
s ( x, y )  1 S (u , v)
 1 H (u, v) Fi (u, v)  H (u, v) Fr (u, v)
 1 H (u, v) Fi (u, v)  1 H (u, v) Fr (u, v)
 i '( x, y )  r '( x, y )

g ( x, y )  e s ( x , y )  ei '( x , y )e r '( x , y )  i0 ( x, y )r0 ( x, y )

11/17/2023 73
Homomorphic Filtering

The illumination component of an image generally is


characterized by slow spatial variations, while the
reflectance component tends to vary abruptly

These characteristics lead to associating the low


frequencies of the Fourier transform of the logarithm of an
image with illumination the high frequencies with
reflectance.
11/17/2023 74
Homomorphic Filtering


H (u , v)  ( H   L ) 1  e
 c  D 2 ( u ,v )/ D02 
   
  L

Attenuate the contribution


made by illumination and
amplify the contribution made
by reflectance

11/17/2023 75
 L  0.25
Homomorphic
H  2
Filtering
c 1
D0  80

11/17/2023 76
Homomorphic Filtering

11/17/2023 77
Selective Filtering

Non-Selective Filters:
operate over the entire frequency rectangle

Selective Filters
operate over some part, not entire frequency rectangle
• bandreject or bandpass: process specific bands
• notch filters: process small regions of the frequency
rectangle

11/17/2023 78
Selective Filtering:
Bandreject and Bandpass Filters

H BP (u , v)  1  H BR (u, v)

11/17/2023 79
Selective Filtering:
Bandreject and Bandpass Filters

11/17/2023 80
Selective Filtering:
Notch Filters
Zero-phase-shift filters must be symmetric about the origin.
A notch with center at (u0, v0) must have a corresponding
notch at location (-u0,-v0).

Notch reject filters are constructed as products of highpass


filters whose centers have been translated to the centers of
the notches.
Q
H NR (u, v)   H k (u, v) H  k (u, v)
k 1

where H k (u, v) and H - k (u, v) are highpass filters whose centers are
at (uk , vk ) and (-uk , -vk ), respectively.
11/17/2023 81
Selective Filtering:
Notch Filters
Q
H NR (u , v)   H k (u , v) H  k (u , v)
k 1

where H k (u , v) and H - k (u , v) are highpass filters whose centers are


at (uk , vk ) and (-uk , -vk ), respectively.

A Butterworth notch reject filter of order n


3 1  1 
H NR (u , v)    2n   2n 
k 1 1   D0 k / Dk (u , v )   1   D0 k / D k (u , v )  
  
2 1/2
Dk (u , v)  (u  M / 2  uk )  (v  N / 2  vk ) 
2

2 1/2
D k (u , v)  (u  M / 2  uk )  (v  N / 2  vk ) 
2

11/17/2023 82
Examples:
Notch
Filters (1)

A Butterworth notch
reject filter D0 =3
and n=4 for all
notch pairs

11/17/2023 83
Examples:
Notch Filters
(2)

11/17/2023 84
11/17/2023 85

You might also like