Unit 5 - Image Transforms
Unit 5 - Image Transforms
Image Transforms
Why Image Transform?
Transformed image
• 2D image : 𝑇
𝐹=𝐴. 𝑓 . 𝐴
𝐹=𝐴. 𝑓 ′
¿| 𝑓 |∨¿ ¿
2
Energy in original image
¿|𝐹|∨¿ ¿
2
Energy in Transformed image
| | 2
| | 2
¿ 𝑓 ∨¿ =¿ 𝐹 ∨¿ ¿¿
Applying 1D transform
to row first and then
column gives same
result as applying 1D
transform to column first
and row first
Fourier Transform
Fourier Transform
What do you mean by
frequency of an image ?
Let us revisit frequency of a
sine wave
Practically, the most frequent pixels will be put in one corner and
the least frequent pixels will be in the opposing corner.
Equation of DFT:
𝑁 −1
1
Equation of IDFT: 𝑥 ( 𝑛) =
𝑁
∑ 𝑋 (𝑘)𝑒 𝑗 2 𝜋 𝑛𝑘/ 𝑁
k = 0,1,2,..,N-1
𝑘=0
T* conjugate of T
Matrix representation of the
FT Equation
Equation of DFT:
𝑗𝜃
𝑆𝑖𝑛𝑐𝑒 , 𝑒 =𝑐𝑜𝑠 𝜃+ 𝑗 𝑠𝑖𝑛 𝜃
[ ]
1 1 1 1
1 − 𝑗 −1 𝑗
𝑇=
1 −1 1 −1
1 𝑗 −1 − 𝑗
DFT Transform matrix
Order 2
=
Order 4
Normalized Transform
=
To find DFT of 1D sequence
Equation of DFT:
𝑋 =𝑇 . 𝑥 ′
Numericals
Lab to compute
t in
u DFT using Matrix method
gh
Ta
1. Compute the DFT of x(n) = {1 1}
𝑋=𝑇 . 𝑥 ′
=
b
Numericals
t i
L
n
a
to compute
h
Ta DFT using Matrix method
ug
N order of DFT
(number of samples)
x=
x=
b
Numericals
t in
La
to compute
h
Ta DFT using Matrix method
ug
𝐹 =𝑇 . 𝑓 ′
Check these two should have same value with sign reversal of j term
ab
L
ght in Compute IDFT of
au
T
1
𝑥= 𝑇 ∗. 𝑋
𝑁
=
== =
ab
ht in
L Example of DFT
g
auCompute
T 2 D DFT of the 4 x 4 gray scale
image given below
[ ]
1 11 1
1 11 1
𝑓 (𝑥 , 𝑦 )=
1 11 1
1 11 1
[ ]
1 1 1 1
1 − 𝑗 −1 𝑗
𝑇=
1 −1 1 −1
1 𝑗 −1 − 𝑗
x x
[ ]
16 00 0
0 00 0
¿
0 00 0
0 00 0
ab
Meaning
ht in
L
ug
Ta As seen the input image has no
variations.
It has a constant shade across
[ ]
1 11 1
1 11 1 Input all pixels (known as dc term)
𝑓 (𝑥 , 𝑦 )=
1 11 1
1 11 1 image
The value of F(0,0) in the
transformed image is always the
dc component (average
[ ]
16 00 0
0 00 0 Output brightness of the image).
𝐹 ( 𝑥 , 𝑦 )=
0 00 0
0 00 0 image
The value of F(0,0) is always
the highest in a transformed
image
DC Component
[ ]
16 00 0
0 00 0
𝐹 ( 𝑥 , 𝑦 )=
0 00 0
0 00 0
ab
t
Find
i
L
n the DFT for given 2d
gh
Ta
u
image
x=
F(u,v)=A f(x,y) AT
1 1 1 1
1 j 1 j
A
1 1 1 1
1 j 1 j
ab
L
t in
gh
au F(u,v) = A f(x,y) AT
T
=
][ ] [
1 1 1 1 0 01 0 0 0 4 0
1 − 𝑗 −1 𝑗 0 01 0 0 0 0 0
=¿ ⇒
1 −1 1 −1 0 01 0 0 0 0 0
1 𝑗 −1 − 𝑗 0 01 0 0 0 0 0
ab
L
t in
gh
au
T
=
ab
IDFT in
L example (N = number of rows×number of
t
columns)
h
ug 1
Ta 𝑓 = 𝑻 𝐹𝑻
𝑵𝟐
X= T=
X=
ab
L
x=t in
gh
au
T
[ ][ ][ ]
1 1 1 1 4 −44 −4 4 −4 4 −4
1 𝑗 −1 − 𝑗 0 0 0 0 4 −4 4 −4
=
1 −1 1 −1 0 0 0 0 4 −4 4 −4
1 − 𝑗 −1 𝑗 0 0 0 0 4 −4 4 −4
x==
x=
ab
L
ht in Compute the 2D DFT of
ug
Ta
image x
ab
L
t in
gh
au
T
Addition of all
pixel values
Dc component /
coefficient
𝑅 (𝑢, 𝑣) 𝐼 (𝑢 , 𝑣)
−1 𝐼 (𝑢 , 𝑣 )
∅ (𝑢 )=𝑡𝑎𝑛
|𝐹 (𝑢 , 𝑣 )|= √ 𝑅 (𝑢 , 𝑣)
2 2
+ 𝐼 (𝑢 , 𝑣 ) 𝑅(𝑢 , 𝑣)
ab
L
t in
gh
au
T
different
Demonstration
Take two pictures, swap the phase transforms and compute the
DC coefficient is at the
center for better
understanding of the
transformed iamge.
[ ] [ ]
1 11 1 16 00 0
0 00 0
𝑓 (𝑥 , 𝑦 )=
1 11 1 𝐹 ( 𝑥 , 𝑦 )=
1 11 1 0 00 0
1 11 1 0 00 0
Example of Frequency
Spectrum of
Image
images
Fourier Spectrum
Variations in
intensity in y
direction
DC term
Average Intensity
Variations in intensity
in x direction
ab
L Two important things to improve
t in
gh visibility of the transformed image
u
Ta
Use of Centered
Representations of
Frequency information
Log transformation and
centering of DFT
Centering f’(x,y) = (-1)x+y f(x,y) To get log frequencies at the center
Log
Transformation
of the
Magnitude
Spectrum
DC
coefficients
Image DFT
Log
Centered Transformed
DFT and Centered
DFT
Log transformation and
centering of DFT
Generally, DC coefficient, F(0,0) is much larger than AC coefficients,
F(u,v)
Large DC coefficients dominates AC coefficients
Therefore, AC coefficients may approximate to zero
Log transformation reduces large range of DFT to the smaller
range
Ex. F(0,0)= 105 and F(100,50)=10
Log10{F(0,0)}=5
Log10{105}=5
Log10{F(100,50)}=1
Log10{10}=1
NOTE :
Transformed image
𝑇
1D image : 𝐹=𝐴. 𝑓
• 2D image : 𝑇
𝐹=𝐴. 𝑓 . 𝐴
Transform, A has to be suitably selected : DFT, DCT, Walsh, Hadamard, etc
Order N=4
Order N=1 Order N=2
Hadamard Transform Matrix
The Hadamard matrix of any order can be
generated recursively as:
HN HN
H 2N
HN HN
Hadamard Transform Matrix
1 1
H 2
1 1
HN HN
H 2N
HN H N
1 1 1 1
1 1 1 1
H 4
1 1 1 1
1 1 1 1
Computation of Hadamard
transform
1
√4
Q. Prove that hadamard
transform is a orthogonal
matrix
i.e to prove that
A.AT = I
Where
11
AA==
√√44
A.AT = I
Where
1
A=
√4
Show that hadamard matrix
of order 2 is unitary
i.e. A*T= A-1
A A*T= 1
A=
Find the hadamard transform
of
f = [1 2 3 4]
Formula : F = A . fT
Find inverse of F=[10 -2 -4 0]
F = AT . F
Q. Compute the hadamard transrform for the given image matrix
2 4 1 6
3 1 1 1 1
2 1 4 1 1 1 1
f
6 5 3 2 A H 4 1
1 1 1 1
1 2 4 3
1 1 1 1
√4
F(u,v)=A f(x,y) AT
Q. Compute the hadamard transrform for the given image matrix
2 4 1 6
3 2 1 4 1 1 1 1
f 1 1 1 1
6 5 3 2
A H 4 1
1 2 4 3 1 1 1 1
1 1 1 1
√4
F(u,v)=A f(x,y) AT
49 7 1 5
9 3 9
1 1
F
3 11 3 9 4
3 7 11 3
Find inverse of
49 7 1 5
9 3 9 1
1
F
4 3 11 3 9
3 7 11 3
f(x,y)=AT F(u,v) A
Hadamard matrix is
sampling the square and
rectangular
Advantage
Immunity to channel errors
bandwidth reduction.
Bandwidth reduction is possible because the image
energy which is uniformly distributed in the spatial
domain, tends to be concentrated near the origin of the
Hadamard domain.
Many of the higher spatial frequency components are
of very low magnitude, and need not to be transmitted.
Transformed Image
What do you mean by average
brightness?
In Walsh, Hadamard and
cosine Transform
The top left corner F(0,0) of the
transformed image is associated with
the zero frequency.
Zero frequency is referred to as
DC component (average
brightness of, the image)
A= 1
[
1
1 −1 ]
How to get Walsh transform
matrix from Hadamard
Transform Matrix ?
Generating Walsh Transform
Matrix from Hadamard
Transform
a Walsh matrix is formed Matrix
by arranging the
rows of Hadamard transform in such a way
that the frequencies are in natural order
Hadamard No. of sign change
transform :
0
3
1
2
Hadamard Transform
0
3
1
2
Walsh Transform
[ ]
1 11 1 0
𝐴= 1 1−1 −1 1
1 −1− 11 2
1 −11 −1 3
Walsh Transform
1 1 1 1
1 1 -1 -1
1 -1 -1 1
1 -1 1 -1
Computation of Walsh
transform
1D image :
𝑇
𝐹=𝐴. 𝑓
Find the walsh transform of
the 2D image given below:
F(u,v)=A f(x,y) AT
Contd….
Slant Transform
Orthogonal transform
Transform is generated by sampling by the
sawtooth waveforms
Order N=2n
The slant transform provides high energy
compaction property
Used for detecting diagonal edges
Fast computational algorithm is possible
Slant transform matrix of
order
2 x 2 slant transform matrix2
is identical to the
Hadamard transform matrix
1 1 1
S 21 1 1
2
Construction of slant Matrix
Slant transform of order N can be obtained by recursive operation
Construction of slant Matrix
Slant transform of order N can be obtained by recursive operation
Construct the Slant transform matrix
order N=4
1 0 1 0
a4 b4 -a4 b4 S2 0
1
𝑆4= 0 1 0 1 0 S2
√2
-b4 a4 b4 a4
Construct the Slant
transform matrix order N=4
1 0 1 0
a4 b4 -a4 b4 S2 0
1
𝑆4= 0 1 0 1 0 S2
√2
-b4 a4 b4 a4
0.89
0.45
1 0 1 0
a4 b4 -a4 b4 S2 0
1
𝑆4= 0 1 0 1 0 S2
√2
-b4 a4 b4 a4
1 0 1 0
1 1 0 0
0.89 0.45 -0.89 0.45
1 1 -1 0 0
𝑆4= 1
√2 0 1 0 1
√2 0 0 1 1
-0.45 0.89 0.45 0.89 0 0 1 -1
1 1 1 1
3 1 1 3
1 5 5 5 5
S 22
2 1 1 1 1
1 3 3 1
5 5 5 5
Properties of Slant
Transform
Real and orthogonal
Fast transform
Good energy compaction
Q. Compute the Slant
transform of the given image
f ( x , y)= 1
34
2
[ ] 1
2
1 1
[
1 1
3 4 2]
1 2 1 1 1
1 1
F = S. f. ST
F ( x , y)= 5 − 1
−20 [ ]
1 1 1
S 21 1 1
2
Q Find inverse slant
transform of F 1 1 1 5 1 1 1 1
f = S . f. S
T
1 1 2 0 2 1 1
2
F ( x , y)= 5 −
−20
1
[ ] f ( x , y)= 1
[ ]
2
34
1 1 1
S 21 1 1
2
Q. Find slant transform of given
1D image
f = {1 2 2 1}
1D image :
𝑇
𝐹 =𝑆 . 𝑓
f is a 1 x 4 matrix so requires transform of order 4
1 1 1 1
3 1 1 3
1 5 5 5 5
S
2 1 1 1 1
1 3 3 1
5 5 5 5
Contd….
𝑇
𝐹 =𝑆 . 𝑓
1 1 1 1
3 1 1 3 1
2
1 5 5 5 5
2 1 1 1 1 2
1 3 3 1
1
5 5 5 5
3
0
F
1
0
Q. Find inverse slant transform
of given 1D image
f = {3 0 -1 0}
1D image :
𝑇
𝑓 =𝑆 . 𝐹
F is a 1 x 4 matrix so requires transform of order 4
1 1 1 1
3 1 1 3
1 5 5 5 5
S
2 1 1 1 1
1 3 3 1
5 5 5 5
Contd….
𝑇
𝑓 =𝑆 . 𝐹
3 1
1 1 1
5 5 2
1 1 3
1 2
1 5 5
2 1 1 3 1
1
5 5
1 3 1
1
5 5
1
2
f
2
1
Discrete Cosine Transform
Real valued
Unitary
orthogonal
Basis vectors are sampled form of cosine
signal
Widely used for image compression
2-D DCT
𝑓 (𝑥 , 𝑦 ) Input image
𝐹 (𝑢, 𝑣 ) Output image
N1 N1
(2 x 1)u (2 y 1)v
F(u , v) (u ) (v) f(x, y) cos cos
x 0 y 0 2N 2N
1 1
ifu 0 ifv 0
N N
(u ) , (v)
2 2
ifu 0 ifv 0
N N
u = 0, 1, …, N-1
v = 0, 1, …, N-1
2D – DCT Transform Matrix
F (0) 0.5 0.5
(A)
0.5 0.5 f (0)
F (1) 0.6532 0.2706 0.2706 0.6532 f (1)
F (2) 0.5 0.5 0.5 0.5 f (2)
F (3) 0.2706 0.6533 0.6533 0.2706 f (3)
• A AT=I
• Transform is separable, i.e. DCT transform of rows
and columns of image can be computed separately
• Or, F = AfAT
• f = AT F A
Example DCT Transform of 2D
image
Determine DCT of the following image matrix
and prove that DCT has good energy
compaction property
𝑓 =¿
Computation of 2-D DCT
matrix
𝑓 =¿
0.5 0.5 0.5 0.5
0.6532 0.2706 0.2706 0.6532
A
0.5 0.5 0.5 0.5
0 . 2706 0 . 6533 0 . 6533 0 . 2706
• Low frequency
coefficients have High frequency coefficients
higher values than
higher frequencies
DCT Coefficients
DCT compression for 768x768
image
• Original image
has 589824
pixels 589824 coefficients
• DCT of image as are stored and used
589824 pixels for inverse DCT
Example DCT
• Original image
has 589824 589824 coefficients
pixels are stored and used
• DCT of image as for inverse DCT
589824 pixels
𝑓 =[ 1 ,2 , 3 , 4 ]
Computation of 2-D DCT
matrix
=[ 1 ,2 , 3 , 4 ]
0 .5 0 .5 0 .5 0 .5 1
0.6532 0.2706 0.2706 0.6532 2
Af
T
0 .5 0 .5 0 .5 0 .5 3
𝑇
𝐹=𝐴. 𝑓 0 . 2706 0 . 6533 0 . 6533 0 . 2706 4
This shows that almost 100% of the total energy is avilable in only first two
coefficeints.
So we need to preserve the first two coefficients too get the original image
This is referred to as ENERGY COMPACTNESS
Karhunen Loeve Transform
(KL Transform / Hotelling
transform)
In DCT / DFT we have a fixed Transformation
matrix which is same for any image
In KL transform, the transformation matrix
depends on the image
It is a statistical based method used for image
compression
So in order to apply KL transform to a image, the
statistical properties of the image is required
(mean, covariance)
KL Transformation
The KL Transform is also known as the Hoteling transform or the Eigen
Vector transform.
The KL Transform has several important properties that make it useful
for image processing particularly for image compression.
The main purpose of image compression is to store the image in fewer
bits as compared to original image, now data from neighboring pixels in
an image are highly correlated.
More image compression can be achieved by de-correlating this data.
The KL transform does the task of de-correlating the data thus
facilitating higher degree of compression
KL Transformation
Forward Transform
X a vector formed from the input image
A KL transformation matrix
mean of the vector X
Inverse Transform
0 0 0
0 0 0
Instead of 1 it maybe shaded
0 0 0 0
0 0 0 0
0 0 1 0
0 1 0 0
0 0 0 0
0 0 0 0
1 2
𝑁 𝑥=1
f(x)
[ ] [ ] [ ]
2 3
𝑓 − 𝜇 = 1 − 1 .5 = − 0.5
1 ❑
2 2.5 − 0. 5
𝑓 2 − 𝜇❑ =
3[ ] [
2 − 1.5 = 0.5
2.5 0.5 ] [ ]
[-0.5 -0.5] =
[0.5 0.5] =
𝑁
1
𝐶 𝑓 = ∑ (𝑓 ¿¿ 𝑥−𝜇)(𝑓 ¿¿ 𝑥−𝜇) ¿¿
′
𝑁 𝑥=1
𝐶𝑓 =
1
2 ([ 0 .25
0.25
0.25
0.25 ] [
+
0 .25
0.25
0.25
0.25 ])
𝐶𝑓 =
1
2 [ 0.5
0.5
0.5
0.5 ]
𝐶𝑓 = [ 0.25
0. 2 5
0.2 5
0.2 5 ]
Step 4 : Eigen Values (
|𝐶 𝑓 − λ 𝐼 |=0
|[ 0 .25
0.25
0.25
0.25 ]
−λ
1
0 [ 0
1
=0
]|
|[ 0 .25
0.25
0.25
0.25
−
λ
0] [ 0
λ
=0
]|
|[ 0 .25 − λ
0.25
0.25
0.25 − λ
=0
]|
2 2
(0.25 − λ) − ( 0.25 ) =0
2 2
(0.25 − λ) − ( 0.25 ) =0
2 2 ❑ 2
(0.25) +( λ) −(2 ×0.25 × λ) − ( 0.25 ) =0
2 ❑
( λ) −(0. 5 × λ) =0
λ ¿
λ= 0 λ=0.5
Step 4 : find the Eigen vector
|𝐶 𝑓 − λ 𝐼 |=0
|[ 0 .25 − λ
0.25
0.25
0.25 − λ ][ ]|=[ 00 ]
𝑥1
𝑥2
|[ 0 .25 − 0
0.25
0.25
0.25 − 0 ][ ]| [ ]
𝑥1
𝑥2
=
0
0
|𝐶 𝑓 − λ 𝐼 |=0
|[ 0 .25 − λ
0.25
0.25
0.25 − λ ][ ]|=0
𝑥1
𝑥2
❑
(− 0.25) 𝑥 +( 0.25) 𝑥 2=0
1 [ ] [ ]
𝑥1
𝑥2
=
1
1
❑
(0. 2 5) 𝑥 2 ❑
𝑥1 = 𝐼𝑓 𝑥 2=1 , 𝑥 1=1
0.25
Step 5 : KL transformation matrix (A)
A = [ eigen vector (λ1 ), eigen vector (λ2 ), eigen vector (λ3 ),…]
A=
KL Transform )
KL Transform )