You are on page 1of 43

Image

Transforms

Feb 18, 19, and March 25, 2019


2

Discrete Fourier Transform (DFT)


• For a discrete signal 𝑓(𝑥) of length 𝑀 (𝑥 = 0 … 𝑀 − 1),
the forward transform (DFT) is
M 1
1 u=0,1,2,…, M-1
F (u ) 
M
 f ( x) exp(i 2ux / M )
x 0
x=0,1,2,…, M-1
M 1
1
F (u ) 
M
 f ( x)[cos(2ux / M )  isin (2ux / M )]
x 0
Both the
signal and
and
andits inverse transform (IDFT) is
the discrete
M 1 spectrum
1
f ( x) 
M
 F (u ) exp(i 2ux / M )
u 0
are complex
values
M 1
vectors of
1
F (u ) 
M
 F (u )[cos(2ux / M )  isin (2ux / M )]
x 0
length M
3

Discrete Fourier Transform (DFT)


M 1
1
F (u ) 
M
 f ( x) exp(i 2ux / M )
x 0
u=0,1,2,…, M-1
x=0,1,2,…, M-1
M 1
1
f ( x) 
M
 F (u ) exp(i 2ux / M )
u 0

• To compute 𝐹(𝑢), we start by substituting 𝑢 = 0 in the


and
exponential term and then summing for all values of 𝑥
• Repeat this process for all 𝑀 values of 𝑢 in order to
obtain the complete Fourier transform
• Each of the 𝑀 terms of 𝐹(𝑢) is called a frequency
component of the transform
4

The Mechanics of Computing DFT

f(0)=1, f(1)=2, f(2)=4, f(3)=4 Similarly, given F(u)


and compute f(x)
M 1
1
F (u ) 
M
 f ( x)[cos(2ux / M )  isin(2ux / M )]
x 0

3
1 1 3
F (0) 
4

x 0
f ( x)[cos(2 0 x / 4)  isin (2 0 x / 4)]   f ( x)
2 x 0
3
1
F (1) 
4
 f ( x)[cos(2x / 4)  isin (2x / 4)]
x 0
and so on….

F(0)=11/2, F(1)=(-3+2i)/2, F(2)=(-1+0i)/2, F(3)=-(3+2i)/2


5

Discrete (cosine and sine) Basis Functions


M 1
1
F (u ) 
M

x 0
f ( x) exp(i 2ux / M ) u=0,1,2,…, M-1
x=0,1,2,…, M-1
M 1
 f (x)
1

M
 f ( x)[cos(2ux / M )  i sin(2ux / M )]
x 0

CuM ( x)  C xM (u )  cos(2ux / M )  cos(u x)

SuM ( x)  S xM (u )  sin(2ux / M )  sin(u x)


and
• Each of these 1D basis function is periodic with 𝑀 and has a
discrete frequency (wave number) 𝑢, which corresponds to the
angular frequency 𝜔𝑢

• Discrete function 𝑓(𝑥) is decomposed into a finite sum of 𝑀


discrete cosine and sine functions whose weights (or
amplitudes) are determined by the DFT coefficients in 𝐹(𝑢)
S uM ( x)  S xM (u )  sin(2ux / M )
8
S 0 ( x) 6
𝑢=0 𝑢=1
Exactly 1 full
8
S ( x)
0
S18 ( x) cycle over the
signal length 8

𝑥 𝑥 𝑥 𝑥

Discrete Basis Functions


𝑢=2 𝑢=3
8 8
C ( x)
2
8
S ( x) C ( x)
6 S 38 ( x)
2

𝑥 𝑥 𝑥
𝑥

For signal length M = 8 and wave nos u = 0 to 7


𝑢=5
𝑢=4 C38 ( x) S 58 ( x)
8 8
C ( x)
4 S ( x)
4

𝑥 𝑥
𝑥 𝑥

𝑢=7
𝑢=6 8
8
C ( x)
5 S 78 ( x)
C ( x)
4 S 68 ( x)

𝑥
𝑥
𝑥 𝑥
7

Discrete Basis Functions: Another Example


8

Aliasing in Signal Space


Another manifestation of the sampling theorem

C18 ( x)
𝑢=1
• For signal length 𝑀 = 8, the discrete
C178 ( x)
sine and cosine basis functions for
𝑥
the wave nos 𝑢 = 1, 9, 17 (round
𝑥
dots) are all identical, although
their continuous counterparts are
different
𝑢=9
C18 ( x) S18 ( x) • Obviously, 𝑢 = 4 is the max freq.
component that can be represented
𝑥 𝑥
by a discrete signal of length 𝑀 = 8
• Any discrete function with a higher
𝑢 = 17
frequency (𝑢 = 5. . 7 in this case)
C98 ( x)
S178 ( x) has an identical counterpart with a
lower wave number and thus
𝑥 𝑥 cannot be reconstructed from the
sampled signal!
10

2D Impulse and Its Shifting Property

 

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

F (u , v)
ATZ sin(T ) sin(vZ )

MN (T ) (vZ )
11

2-D Discrete Fourier Transform


• In 2-D case, the DFT pair (image 𝑓(𝑥, 𝑦) of
size 𝑀 × 𝑁) is:
M 1 N 1
1
F (u , v) 
MN
 f ( x, y) exp(i 2 (ux / M  vy / N ))
x 0 y 0

and u=0,1,2,…,M-1 and v=0,1,2,…,N-1


M 1 N 1
1
f ( x, y ) 
MN
 F (u, v) exp(i 2 (ux / M  vy / N ))
u 0 v 0

u·x  1/M 𝑥 = 0, 1, 2, … , 𝑀 − 1
v·x  1/M 𝑦 = 0, 1, 2, … , 𝑁 − 1
12

2D cosine functions for 𝑀 = 𝑁 = 16, for 𝑢, 𝑣 = 0. . 3


𝑦 𝑢=0 𝑦 𝑢=1 𝑦 𝑢=2
𝑦 𝑢=3

𝑣=0 𝑣=0

𝑥 𝑥 𝑥 𝑥
𝑦 𝑦
𝑦 𝑦

𝑣=1 𝑣=1

𝑥 𝑥 𝑥 𝑥
𝑦 𝑦 𝑦 𝑦

𝑣=2 𝑣=2

𝑥 𝑥 𝑥 𝑥
𝑦 𝑦
𝑦 𝑦

𝑣=3 𝑣=3

𝑥 𝑥 𝑥
𝑥
13

A Useful Analogy
• Compare Fourier transform to a glass prism

• Fourier transform may be viewed as


―mathematical prism‖ that separates a
function into various components based on
frequency content
• When we consider light, we talk about its
spectral or frequency content
• Similarly, the Fourier transform lets us
characterize a function by its frequency
content
14

Some Properties of the 2D DFT


• Similarity
• Linearity
• Separability
• Translation and Rotation
• Periodicity
• Symmetry
• DFT as Spatial Filter
• Convolution
Follow the discussion done in the class …
15

Periodicity and Centered Representation

(a) Original Image (b) Non-centered spectrum (c) Centered spectrum


16

Power Spectrum (Spectral density)


• Magnitude of the complex valued Fourier spectrum
𝑃 𝑢 = 𝐹(𝑢, 𝑣) 2

• Phase: measure of displacement of the various


sinusoids wrt their origin (gives shape information)
• Power spectrum
– Specifies the energy that individual frequency components in the
spectrum contribute to the signal
– Real valued and +ve; often used for graphically displaying the
results of FT
– All phase information is lost in the power spectrum, the original
signal cannot be reconstructed from the power spectrum alone
– Insensitive to shifts of the original signal  efficiently used for
comparing signals
17

Power Spectrum
• Magnitude of the complex valued Fourier
spectrum
F (u, v)  R(u, v)  j  I (u , v)
Polar coordinate
𝐹 𝑢, 𝑣 = 𝐹(𝑢, 𝑣) 𝑒 𝑖𝜑(𝑢,𝑣) F (u, v)  F (u, v) exp( j (u, v))
Magnitude: F (u, v)  [ R (u, v)  I (u , v )]
2 2 1/ 2

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

 R(u, v) 
Power spectrum: 𝑃 𝑢 = 𝐹(𝑢, 𝑣) 2
(or Spectral density)
18

Power Spectrum
• As all computations are carried out for the
discrete variables 𝑢 and 𝑣, therefore F (u, v) ,
 (u, v) and P(u, v) are arrays of size 𝑀 × 𝑁

M 1 N 1
1
 f ( x, y)
Even
F (u , v)  F (u ,v)
symmetry F (0,0) 
Odd
MN x 0 y 0
 (u, v)    (u,v)
symmetry
Zero frequency term

• The constant is usually M 1 N 1


MN
large, F (0,0) is the largest
component of the

MN
 f ( x, y)
x 0 y 0
spectrum 
• F (0,0) - the dc component  MN f ( x, y )
19

Displaying Transforms
• As elements are complex numbers, we can view
magnitudes F (u, v) directly
• Displaying magnitudes of Fourier transforms called
spectrum of the transform
• Problem: DC component much larger than other
values
• Displays white dot in middle surrounded by black
• So stretch transform values by displaying log of
transform
20

Fourier Transform – Examples (1)


• Suppose we have a constant image of all 1’s, 𝑓(𝑥, 𝑦) = 1
• The DFT yields just a DC component, 0 everywhere else
• In this example, DC component is sum of all elements = 64

• Consider DFT of image with single edge


• For display, DC component shifted to center
• Log of magnitudes of Fourier Transform displayed

Image DFT
Fourier Transform – Examples (2)
22

Fourier Transform – Examples (3)


• A Circle
• Note: Ringing caused by sharp cutoff of circle
• Ringing does not occur if circle cutoff is gentle
Fourier Transform – Examples (4)
Fourier Transform – Phase Angle

In general, visual
analysis of phase angle
images yields little
intuitive information

Phase gives shape


information
25

Magnitude and Phase - Summary


• Components of the spectrum determine the
amplitudes of sinusoids that combine to form the
resulting image
– At any freq. in the DFT of an image, a large (small) amplitude
implies a greater (less) prominence of a sinusoid of that frequency
in the image
• Magnitude of 2D DFT – array whose components
determine the intensities in the image
• Phase: measure of displacement of the various
sinusoids wrt their origin
• Phase of 2D DFT – array of angles that carry much
of information about where discernable objects
are located in the image
Fourier Transform – Role of Phase Angle

𝐹 𝑢, 𝑣
= 𝐹(𝑢, 𝑣) 𝑒 𝑖𝜑(𝑢,𝑣)

Inverse DFT using only phase information (with |F(u, v)| = 1 in the equation)
Inverse DFT using only spectrum (set phase angle to 0 in the equation)
27

Fourier Transform – Another Example

FT

IFT
28

Fourier Transform – Another Example


The central part of FT,
i.e., the low frequency
components are IFT
responsible for the
general gray-level
appearance of an
image

The high frequency


components of FT
are responsible for IFT
the detail
information of an
image
Fourier Transform and Convolution

Spatial Domain (x) Frequency Domain (u)


g  f h G  FH
g  fh G  F H

So, we can find 𝑔(𝑥) by Fourier transform

g  f g 
IFT FT FT

    g
30

Convolution Theorem
G(u,v)=F(u,v)H(u,v) Multiplication in Frequency Domain

g(x,y)= f(x,y)*h(x,y) Convolution in Spatial Domain

f(x,y)*h(x,y)↔ F(u,v)H(u,v)

g(x,y)= f(x,y).h(x,y) Multiplication in Spatial Domain

G(u,v)= F(u,v)*H(u,v) Convolution in Frequency Domain

f(x,y).h(x,y)↔ F(u,v)*H(u,v)
31

Convolution of Two Functions


Convolution of two simple 1-Dfunctions
Requirement of Function
Padding
33

2D DFT: Summary

Consider the definition of Fourier transform followed …


34

2D DFT: Summary

Consider the definition of Fourier transform followed …


35

2D DFT: Summary

Consider the definition of Fourier transform followed …


36

Fast Fourier Transform

Follow Class Notes


37

Discrete Cosine Transform


• Relationship between DCT and FFT
– DCT is actually a cut-down version of the Fourier
Transform or the Fast Fourier Transform (FFT)
– Computationally simpler than FFT
– Real but Not! Real part of DFT
• Fast Transform – Excellent Energy compaction
• Orthogonal
– tend to decorrelate the components of a given signal
– tend to redistribute the energy contained in the
signal so that most of energy is contained in a small
number of components
• DCT — Effective for Multimedia Compression (MUCH
more commonly used (than FFT) in Multimedia)
38

1D Discrete Cosine Transform


𝑀−1
2 π 2𝑥 + 1 𝑢
𝐹 𝑢 = 𝐶 𝑢 𝑓 𝑥 cos
𝑀 2𝑀
𝑥=0

1 𝑓𝑜𝑟 𝑢 = 0
For 𝑢 = 0, … , 𝑀 − 1 where 𝐶 𝑢 = 2
1 𝑜𝑡𝑕𝑒𝑟𝑤𝑖𝑠𝑒

𝑀−1
2 π 2𝑥 + 1 𝑢
𝑓 𝑥 = 𝐶 𝑢 𝐹 𝑢 cos
𝑀 2𝑀
𝑥=0

1 𝑓𝑜𝑟 𝑢 = 0
For 𝑥 = 0, … , 𝑀 − 1, where 𝐶 𝑢 = 2
1 𝑜𝑡𝑕𝑒𝑟𝑤𝑖𝑠𝑒

• All DCT basis function are thus periodic over the length 2𝑀
• DCT can also be computed in 𝑂(𝑀𝑙𝑜𝑔2𝑀) time using FFT
• DCT as spatial filter
39

1D DCT Basis Functions (M=8)


40

2D Discrete Cosine Transform


𝑀−1 𝑁−1
2 π 2𝑥 + 1 𝑢 π 2𝑦 + 1 𝑣
𝐹 𝑢, 𝑣 = 𝐶 𝑢 . 𝐶(𝑣) 𝑓 𝑥, 𝑦 cos cos
𝑀𝑁 2𝑀 2𝑁
𝑥=0 𝑦=0

For 𝑢 = 0,1, … , 𝑀 − 1 and 𝑣 = 0,1, … , 𝑁 − 1, where

1 𝑓𝑜𝑟 𝑘 = 0
𝐶 𝑘 = 2
1 𝑜𝑡𝑕𝑒𝑟𝑤𝑖𝑠𝑒

• 2D DCT is linear and separable

8 x 8 DCT basis functions


41

Discrete Hadamard Transform


• The Hadamard transform share a significant
computational advantage over the previously
considered DFT, DCT and also DST transforms

• Hadamard unitary matrix of order n is the N×N matrix


(N = 22), generated by the following iteration rule:
𝐻𝑛 = 𝐻1 ⊗ 𝐻𝑛−1

where
1 1 1
𝐻1 =
2 1 −1
42

Discrete Hadamard Transform


• ⊗ denotes the Kronecker product of two matrices
𝐴 1,1 𝐵 𝐴 1,2 𝐵 ⋯ 𝐴 1, 𝑁 𝐵
𝐴⊗𝐵 = ⋮ ⋮ ⋱ ⋮
𝐴 𝑁, 1 𝐵 𝐴 𝑁, 2 𝐵 ⋯ 𝐴 𝑁, 𝑁 𝐵

where 𝐴(𝑖, 𝑗) is the (𝑖, 𝑗) element of 𝐴, 𝑖, 𝑗 = 1,2 … , 𝑁. Thus,


1 +1 +1 +1
1 1 −1 +1 −1
𝐻2 = 𝐻1⊗𝐻1=
2 1 +1 −1 −1
1 −1 −1 +1

and for n = 3
1 𝐻2 𝐻2
𝐻3 = 𝐻1⊗𝐻2 =
2 𝐻2 −𝐻2
43

Discrete Hadamard Transform


• It is not difficult to show the orthogonality of
𝐻𝑛, 𝑛 = 1,2, … , that is,
𝐻𝑛−1 = 𝐻𝑛𝑇 = 𝐻𝑛
• For a vector 𝑋 of 𝑁 samples and 𝑁 = 2𝑛, the
transform pair is
𝑌 = 𝐻𝑛 𝑋, 𝑋 = 𝐻𝑛 𝑌
• The 2-D Hadamard transform is given by
𝑌 = 𝐻𝑛 𝑋𝐻𝑛 , 𝑋 = 𝐻𝑛 𝑌𝐻𝑛
• The Hadamard transform also has good energy packing
properties and used for data encryption and video
compression
• Fast algorithms for its computation in subtractions
and/or additions are also available
References
• Digital Image Processing - An Algorithmic
Introduction using Java by Dr. Wilhelm Burger
and Dr. Mark J. Burge
• R. C. Gonzalez and R. E. Woods, Digital Image
Processing, Third Edition, Pearson, 2012.
• Computer Vision course by Dr. S. Narasimhan
• https://nptel.ac.in/courses/117104069/chapte
r_7/7_26.html

You might also like