You are on page 1of 69

COL LEGE OF E N GI N E ER I N G ROOR K EE

Established in 1998

Digital Image Processing (TCS-071)

Session: 2020-21

Digital Image Processing


COURSE OBJECTIVE

The aim of this course is,


 Describe and explain basic principles of digital image
processing.
 Design and implement algorithms that perform basic image
processing (e.g. noise removal and image enhancement).
 Design and implement algorithms for advanced image
analysis (e.g. image compression, image segmentation).
 Assess the performance of image processing algorithms and
systems.

Digital Image Processing


Unit 2
Image Enhancement in Frequency Domain

Fourier Transform and the Frequency Domain, Basis of


Filtering in Frequency Domain, Filters – Low-pass, High-
pass; Correspondence Between Filtering in Spatial and
Frequency Domain; Smoothing Frequency Domain
Filters – Gaussian Lowpass Filters; Sharpening Frequency
Domain Filters – Gaussian Highpass Filters;
Homomorphic Filtering.

Digital Image Processing


Digital Image Processing
Image Enhancement in the
Frequency Domain

Digital Image Processing


Objective

• Basic understanding of the frequency


domain, Fourier series, and Fourier
transform.
• Image enhancement in the frequency
domain.

Digital Image Processing


Fourier Series
Any function that periodically
repeats itself can be expressed
as the sum of sines and/or
cosines of different
frequencies, each multiplied
by a different coefficients.
This sum is called a Fourier
series.

Digital Image Processing


Fourier Series

g (t )  a0   an cos nw0t  bn sin nw0t
n 1
t 0 T0
1
a0 
T0  g (t )dt
t0
t 0 T0
2
an 
T0  g (t ) cos nw t dt
t0
0

t 0 T0
2
bn 
T0  g (t ) sin nw t dt
t0
0

Digital Image Processing


Fourier Transform

A function that is not periodic but the area under


its curve is finite can be expressed as the integral
of sines and/or cosines multiplied by a weighing
function. The formulation in this case is Fourier
transform.

Digital Image Processing


Continuous One-Dimensional Fourier Transform
and Its Inverse

 f ( x )e
 j 2ux
F (u )  dx

 Where j  1

 F (u )e
j 2ux
f ( x)  du

• (u) is the frequency variable.
• F(u) is composed of an infinite sum of sine and
cosine terms and…
• Each value of u determines the frequency of its
corresponding sine-cosine pair.
Digital Image Processing
Continuous One-Dimensional Fourier Transform
and Its Inverse
Example
Find the Fourier transform of a gate function (t)
defined by
 1
1 x   u 
 ( x)   2 F (u )   sinc  
0
1
x   2 
 2

x u
- 0.5 0.5
2 4
Digital Image Processing  
Continuous One-Dimensional Fourier Transform
and Its Inverse

Digital Image Processing


Discrete One-Dimensional Fourier Transform and
Its Inverse

• A continuous function f(x) is discretized into a sequence:

{ f ( x0 ), f ( x0  x), f ( x0  2x),..., f ( x0  [ N  1]x)}

by taking N or M samples x units apart.

Digital Image Processing


Discrete One-Dimensional Fourier Transform and
Its Inverse

• Where x assumes the discrete values (0,1,2,3,…,M-1)


then

f ( x)  f ( x0  xx)

• The sequence {f(0),f(1),f(2),…f(M-1)} denotes any


M uniformly spaced samples from a corresponding
continuous function.

Digital Image Processing


Discrete One-Dimensional Fourier Transform and
Its Inverse
M 1 x
1  j 2u
F (u ) 
M
 f ( x )e M u =[0,1,2, …, M-1]
x 0
M 1
1  x x
F (u ) 
M
 f ( x) cos 2u
 M
 j sin 2u 
M
x 0

M 1 u
j 2 x
f ( x)   F (u )e M
u 0
x =[0,1,2, …, M-1]
Digital Image Processing
Discrete One-Dimensional Fourier Transform and
Its Inverse

• The values u = 0, 1, 2, …, M-1 correspond to samples of


the continuous transform at values 0, u, 2u, …, (M-
1)u.
i.e. F(u) represents F(uu), where:
1
u 
Mx
• Each term of the FT (F(u) for every u) is composed of the
sum of all values of f(x)

Digital Image Processing
Discrete One-Dimensional Fourier Transform and
Its Inverse

• The Fourier transform of a real function is generally


complex and we use polar coordinates:

F (u )  R (u )  jI (u )
j ( u )
F (u )  F (u ) e
F (u )  [ R 2 (u )  I 2 (u )]1/ 2
 I (u ) 
 (u )  tan  1

 R (u ) 
Digital Image Processing
Discrete One-Dimensional Fourier Transform and
Its Inverse

|F(u)| (magnitude function) is the Fourier spectrum of


f(x) and (u) its phase angle.

• The square of the spectrum


2
P (u )  F (u )  R 2 (u )  I 2 (u )

is referred to as the Power Spectrum of f(x)


(spectral density).

Digital Image Processing


Discrete 2-Dimensional Fourier Transform

• Fourier spectrum: 
F (u , v)  R (u, v)  I (u , v)
2 2

1/ 2

 I (u , v) 
• Phase:  (u, v)  tan  1

 R (u , v ) 

2
• Power spectrum: P (u , v)  F (u , v)  R 2 (u , v)  I 2 (u , v)

Digital Image Processing


Discrete One-Dimensional Fourier Transform and
Its Inverse

Digital Image Processing


Time and Frequency Resolution and Sampling
Fmax = 100 Hz
What is the sampling rate (Nyquist)?
What is the time resolution?
What is the frequency resolution?
What if the sampling rate is higher
than the Nyquist sampling rate?
What if we take samples for two
seconds with the Nyquist sampling
rate?

Digital Image Processing


1 second
Discrete Two-Dimensional Fourier Transform and
Its Inverse
M 1N 1 x y
1  j 2 ( u v )
F (u , v) 
MN
  f ( x, y )e M N

x 0 y 0

M 1N 1 u v
j 2 ( x  y )
f ( x, y )   F (u , v)e M N

u 0 v 0

 2
F (u , v)  R (u , v)  I (u , v) 2

1/ 2

Fourier Spectrum
Digital Image Processing
Discrete Two-Dimensional Fourier Transform and Its
Inverse

M 1N 1
1
F (0,0) 
MN
  f ( x, y )
x 0 y 0

F(0,0) is the average intensity of an image

Digital Image Processing


Discrete Two-Dimensional Fourier Transform and Its
Inverse

Use Matlab to generate the above figures

Digital Image Processing


Frequency Shifting Property of the Fourier Transform

If
g (t )  G ( )
then
j 0 t
g (t )e  G (  0 )

x y
j 2 ( u 0  v0 )
f ( x, y ) e M N
 F (u  u0 , v  v0 )
Digital Image Processing
Frequency Shifting Property of the Fourier Transform

Digital Image Processing


Basic Filtering in the Frequency Domain using Matlab
function Normalized_DFT = Img_DFT(img)
img=double(img); % So mathematical operations can be conducted on
% the image pixels.
[R,C]=size(img);
for r = 1:R % To phase shift the image so the DFT will be
for c=1:C % centered on the display monitor
phased_img(r,c)=(img(r,c))*(-1)^((r-1)+(c-1));
end
end
fourier_img = fft2(phased_img); %Discrete Fourier Transform
mag_fourier_img = abs(fourier_img ); % Magnitude of DFT
Log_mag_fourier_img = log10(mag_fourier_img +1);
Max = max(max(Log_mag_fourier_img ));
Normalized_DFT = (Log_ mag_fourier_img )*(255/Max);
imshow(uint8(Normalized_DFT))
Digital Image Processing
Basic Filtering in the Frequency Domain

1. Multiply the input image by (-1)x+y to center the transform


2. Compute F(u,v), the DFT of the image from (1)
3. Multiply F(u,v) by a filter function H(u,v)
4. Compute the inverse DFT of the result in (3)
5. Obtain the real part of the result in (4)
6. Multiply the result in (5) by (-1)x+y
Digital Image Processing
Filtering out the DC Frequency Component

Digital Image Processing


Filtering out the DC Frequency Component

Notch Filter

0 if (u , v)  ( M / 2, N / 2)
H (u , v)  
1 otherwise
Digital Image Processing
Low-pass and High-pass Filters
Low Pass Filter attenuate
high frequencies while
“passing” low frequencies.

High Pass Filter


attenuate low frequencies
while “passing” high
frequencies.

Digital Image Processing


Low-pass and High-pass Filters

Digital Image Processing


Low-pass and High-pass Filters

Digital Image Processing


Low-pass and High-pass Filters

Digital Image Processing


Smoothing Frequency Domain, Ideal Low-pass Filters

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

D(u, v)  (u  M / 2)  (v  N / 2)
2

2 1/ 2

Digital Image Processing


Smoothing Frequency Domain, Ideal Low-pass Filters

M 1N 1
  F (u, v)
2
Total Power PT 
u 0 v 0

The remained percentage  


power after filtration   100   F (u, v) / PT 
Digital Image Processing u v 
Smoothing Frequency Domain, Ideal Low-pass Filters
fc =5
 = 92%

fc =15 fc =30
 = 94.6%  = 96.4%

fc =80 fc =230
 = 98%  = 99.5%
Digital Image Processing
Cause of Ringing

Digital Image Processing


Project #5, Ideal Low-pass Filter
Implement in Matlab the Ideal low-pass filter in the
following equation.
1 if D(u , v)  D0
H (u , v)  
0 if D(u , v)  D0

D (u , v)  (u  M / 2)  (v  N / 2)
2

2 1/ 2

1. You must give the user the ability to specify the cutoff
frequency D0
2. Calculate the The remained percentage power after
filtration.
3. Display the image after filtration
4. Use Elaine image to test your program
Digital Image Processing
Smoothing Frequency Domain, Butterworth Low-pass
Filters

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

Digital Image Processing


Smoothing Frequency Domain, Butterworth Low-pass
Filters
Butterworth Low-pass Radii= 5
Filter: n=2

Radii= 15
Radii= 30

Radii= 80 Radii= 230

Digital Image Processing


Smoothing Frequency Domain, Butterworth Low-pass
Filters

Digital Image Processing


Smoothing Frequency Domain, Gaussian Low-pass
Filters

 D 2 ( u ,v ) / 2 D02
H (u , v)  e
Digital Image Processing
Smoothing Frequency Domain, Gaussian Low-pass
Filters
Gaussian Low-pass Radii= 5

Radii= 15
Radii= 30

Radii= 80 Radii= 230

Digital Image Processing


Smoothing Frequency Domain, Gaussian Low-pass
Filters

Digital Image Processing


Smoothing Frequency Domain, Gaussian Low-pass
Filters

Digital Image Processing


Smoothing Frequency Domain, Gaussian Low-pass
Filters

Digital Image Processing


Sharpening Frequency Domain Filters

Hhp(u,v) = 1 - Hlp(u,v)

Digital Image Processing


Sharpening Frequency Domain Filters

Digital Image Processing


Sharpening Frequency Domain, Ideal High-pass Filters

0 if D(u , v)  D0
H (u , v)  
1 if D(u , v)  D0
Digital Image Processing
Sharpening Frequency Domain, Butterworth High-
pass Filters

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

Digital Image Processing


Sharpening Frequency Domain, Gaussian High-pass
Filters

 D 2 ( u ,v ) / 2 D02
H (u, v)  1  e
Digital Image Processing
Homomorphic Filtering

Digital Image Processing


Homomorphic Filtering

Digital Image Processing


Convolution

g(t) = k(t)*h(t)
k(t) h(t) g(t)
G(f) = K(f)H(f)

* is a convolution operator and not multiplication


M 1
1
g ( t )  k ( t ) * h( t ) 
M
 k (t  m)h(m)
m 0
k(t)
h(t)
3
2
1
1
t t
-1 Digital Image Processing 1 2 3
Convolution
h(m)
M 1
1
1
g (0) 
M
 k (0  m)h(m)
m 0
m
g(t)
-1

k(-m)

m
Digital Image Processing
Convolution
h(m)

1
g(t)
m
-1

k(1-m)

m
Digital Image Processing
Convolution
h(m)

1
g(t)
m
-1

k(2-m)

m
Digital Image Processing
Convolution
h(m)

1
g(t)
m
-1

k(3-m)

m
Digital Image Processing
Convolution
h(m)

1
g(t)
m
-1

k(4-m)

m
Digital Image Processing
Convolution
h(m)

1
g(t)
m
-1

k(5-m)

m
Digital Image Processing
Convolution
h(m)

1
g(t)
m
-1

k(6-m)

m
Digital Image Processing
2-Dimensions Convolution

M 1 N 1
1
f ( x , y ) h( x , y ) 
MN
  f (m, n)h( x  m, y  n)
m 0 n  0

Digital Image Processing


Correlation

h(t) g(t) = k(t)h(t)


k(t) g(t) G(f) = K(f)* . H(f)
M 1
1
g ( t )  k ( t )  h( t ) 
M
 k (t  m)h(m)
m 0
k(t) g(t)
h(t)
2 2
1 1
t t
-1
Digital Image Processing
Correlation

Digital Image Processing


Convolution

Digital Image Processing


Convolution

Digital Image Processing


Convolution

Digital Image Processing


Convolution

Digital Image Processing


THANK YOU!

Digital Image Processing

You might also like