You are on page 1of 107

1

IMAGE TRANSFORMS
By
Dr. Suvendu Rup
CSE Dept. IIIT Bhubaneswar
Image Transforms
2

Image transforms can be simple arithmetic or complex


mathematical operations on images which convert images from
one representation to another.

Image (NxN) Image (NxN)


{XN} Transform
{YN}

Y=AX

Image (NxN) Inverse Image (NxN)


{YN} Transform {XN}

X=A-1Y

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Applications
3

 Preprocessing
 Filtering

 Enhancement

 Image Compression

 Feature Extraction
 Edge detection
 Corner detection

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Unitary Matrix
4

 Image transformation represents a given image into series


sum of unitary matrices

 A matrix is called unitary if

−1
A =  
A A *T H

Hermitian conjugate

 Unitary Matrices are basis images

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Properties of Unitary Transform y =Ax
5

 Energy Conservation
 || y ||2 = || x ||2

◼ || y ||2 = || Ax ||2= (Ax)*T (Ax)= x*T A*T A x = x*T x = || x ||2

 Rotation
 A unitary transformation is a rotation of a vector in an N-
dimension space, i.e., a rotation of basis coordinates

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
6

 Energy Compaction

 Many common unitary transforms (like DCT, KLT etc.) tend to


pack a large fraction of signal energy into just a few transform
coefficients
 Decorrelation

 Highly correlated input elements ➔ quite uncorrelated output


coefficients
 Covariance matrix E[( y – E(y) ) ( y – E(y) )*T ]

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
What is orthogonal ?
7

 A set of real valued continuous functions


{an(t)} = {ao(t), a1(t),…} is said to be orthogonal over
(t0, t0+T) if
k if m = n
T am (t ). an (t ) dt = 0 if m  n
if k = 1 then an (t ) is orthonormal

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Example
8

 {sinωt, sin2ωt}

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Orthogonal Expansion
9

Any arbitrary signal x(t); {t0, t0+T}


Can be represented by series summation of a set of
orthogonal basis functions.

x(t ) =  cn an (t )
n =0

cn nth coefficient of expansion

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
10


x (t ) = c a
n =0
n n (t ), t 0  t  t 0 + T


  x(t )a
T
m (t ) dt =  c a
T n =0
n n (t ) am (t ) dt

= c0  a0 (t ) am (t ) dt +
T

c1  a1 (t ) am (t ) dt + ... +
T

cm  am (t ) am (t ) dt + ...
T

  x(t )a m
(t ) dt = kcm   x(t )am(t )dt = cm, if k = 1
T
T
Orthonormal Set
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Complete, Closed(orthogonal
11
functions)
There is no signal x(t) with x 2 (t )dt  

 T

such that
 x(t )a (t )dt = 0, n = 0,1,..
T
n

 x(t) with  (t )dt  


x 2

T N −1
xˆ (t ) =  cn an (t )
n =0

Such that  x(t ) − xˆ (t )


2
dt    0

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Discrete Formulation
12

 Let the set of samples represented by {u(n): 0 ≤ n ≤ N-1}


is a vector of dimension N

 Premultiply u by a unitary matrix A of dimension N*N,


we get another vector

v= Au
Transformed vector
Transformation matrix

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
13

In the form of series summation


N −1
v(k ) =  a (k , n)u (n) 0  k  N −1
n =0

where A−1 = A*T


As A is a unitary matrix we can get back u as
N −1
u ( n ) =  a  ( k , n )v ( k ) 0  n  N −1
k =0

The columns ofAT

i.e.,

k 
(a  a (k , n ), 0  n  N − 1 )


T
are called the basis vectors of A

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Example
14

 Let u0  v0  a00 a01 a02 


U =  u1 
V =  v1  A =  a10 a11 a12 
u2  v2  a20 a21 a22 

 00 10
a a a 20 

A−1 = AT =  a01 a11 a21 


a02 a12 a22 
U = A−1V = AT V
  
 0
u  0   00 
v a  10 
a  20 
a
U =  u1  = A−1  v1  =  a01  v0 +  a11  v1 +  a21  v2
u2  v2  a02  a12  a22 
basis vectors b1 b2 b3
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
15

In case of an image, an image can be represented by a set of basis images


Image u (m, n) 0  m, n  N − 1
N −1 N −1
v(k , l ) =  ak ,l (m, n)u (m, n) 0  k , l  N − 1
m =0 n =0

ak ,l (m, n) N × N matrix/ N2 numbers of such matrices

Inverse Transform
N −1 N −1
u (m, n) =  ak,l (m, n)v(k , l ) 0  m, n  N − 1
k =0 l =0

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
16

❑ Set of complete orthonormal discrete basis function satisfies the


following properties

ak ,l (m, n) Orthonormality
N −1 N −1

 ak ,l (m, n)a (m, n) =  (k − k ' , l − l ')



k ',l '
m =0 n =0
Completeness
N −1 N −1

 ak ,l (m, n)ak,l (m' , n' ) =  (m − m' , n − n')


k =0 l =0

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Computational Complexity
17

 To Compute transform coefficient v(k , l )


N −1 N −1
v(k , l ) =  ak ,l (m, n)u (m, n) 0  k , l  N − 1
m=0 n =0

 For each v(k , l ) no. of complex multiplications and additions


~ O(N2), so for all v(k , l )~O(N4) which is quite expensive for
practical size Images.
 How to reduce computation time??

 Using separable unitary transforms

ak ,l (m, n) = ak (m).bl (n)  a(k , m )b(l , n )

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Separable Transforms
18

where ak (m), k = 0,1,..N − 1 are 1D orthonormal sets of basis vectors


bl (n), l = 0,1,..N − 1
should be unitary matrices themselves
In most cases we choose A & B to be same. A  a(k , m) and B = a(l , n)
N −1 N −1
v(k , l ) =  a (k , m) u (m, n) a (l , n); V = AUAT
m =0 n =0
N −1 N −1
u (m, n) =  a  (k , m) v(k , l ) a  (l , n); U = AT VA
k =0 l =0

V = AU A T
V T = A [ AU ]T
 These are called 2D separable transformation
 The 2D transform can be performed first by transforming each column of U
and then transforming each row of the result to obtain rows of V
complexity is 2N3
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Concept of Basis Images
19


 Let ak denotes the kth column of AT
 Define the matrices
  T
A =a a
k ,l k l

 Define the inner product of two NxN matrices F and G


N −1 N −1
F , G =  f (m, n )g  (m, n )
m =0 n =0

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Concept of Basis Images
20

 Then the transformation equation can be written as


N −1 N −1
v(k , l ) =  ak ,l (m, n)u (m, n)  U , Ak,l
m =0 n =0
N −1 N −1
u (m, n) =  ak,l (m, n)v(k , l )
k =0 l =0
N −1 N −1
 U = u (m, n) =  v(k , l ) Ak,l
k =0 l =0

 U is represented by linear combination of N2 Matrices.


 These matrices are called basis images
Ak,l k , l = 0,1, 2..N − 1
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Example
21

1 1 1 1 2
A=  
U =  
2 1 − 1  3 4 
1 1 1  1 2  1 1
Transformed Image V =    
2 1 − 1  3 4  1 − 1
1 4 6 1 1
=   
2 − 2 − 2 1 − 1
 5 − 1
=  
− 2 0 

To get basis images, take outer product of the columns of AT


1  1 1  1 1
 ( )

A0,0 = 1 1 =  
2  1 2  1 1
 1  1 −1 T
A0,1 =   = A1,0
2  1 −1
 1 1 −1
A =  
2  −1
1,1
1 
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
22

 Inverse Transform gives

T 1 1 − 1 5 − 11
 1
A VA =    
2 1 − 1 − 2 0 1 − 1
1  3 − 11 − 1  1 2
=    =  
2  7 − 11 − 1  3 4
= U  Original Image

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Some Transformation Techniques
23

 Discrete Fourier Transform


 Discrete Cosine Transform
 Karhunen-Loeve Transform
 Haar Transform
 Walsh Transform
 Hadamard Transform

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Fourier Transform (1D)
24

Continuous Fourier Transform (CFT)



W ( f ) = Fw(t ) =  w(t ) e − j 2ft
dt
−

W( f ) = X( f )+ j Y( f )
W ( f ) = W ( f ) e j ( f ) Frequency, [Hz]

Phase
Amplitude Spectrum
Spectrum

Inverse Fourier Transform (IFT)



w (t) = F W (f ) =  W (f ) e + j2ft df
-1
−
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Discrete Fourier Transform (1D)
25

Equal time intervals


◼ Discrete Domains
❑ Discrete Time: n = 0, 1, 2, 3, …………, N-1
❑ Discrete Frequency: k = 0, 1, 2, 3, …………, N-1
Equal frequency intervals

◼ Discrete Fourier Transform


N −1  2 
− j  nk
X [ K ] =  x[n] e  N 
; K = 0, 1, 2,….., N-1
n =0

◼ Inverse DFT
N −1  2 
1 j  nk
x[n] =
N
 X [K ] e
K =0
 N 
; n = 0, 1, 2,….., N-1

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
2D – Discrete Fourier Transform
26

▪ Image: f(x, y), 0≤x≤N-1, 0≤y≤N-1


 xu yv 
− j 2  + 
▪ Transform kernel: g ( x, y, u , v) = e  N N 

▪ Discrete Fourier Transform of f(x, y)is


N −1 N −1  ux vy 
− j 2  + 
 f (x, y )e
1
F (u , v) = N N
N x =0 y =0

N −1 N −1  ux vy 
j 2  + 
f ( x, y ) =
1
N
 F (u, v)e
u =0 v =0
 N N 

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
27

In general, Transform kernel can be represented as:


2 2
−j ux + vy
−j (ux + vy )
wN = e N
w N =e N

Discrete Fourier Transform of f(x, y) can be


represented as

N −1 N −1
f ( x, y )wNux + vy
1
F (u , v) =
N
 x =0 y =0

N −1 N −1
f ( x, y ) =
1
N
 F (u ,
u =0 v =0
v ) wN
− (ux + vy )

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
28

Let R(u,v), I(u,v) be real part and imaginary part of


F(u,v)
Modulus: (
F (u , v) = R (u , v ) + I (u , v )
2 2
)12

 I (u , v ) 
Phase:  (u , v) = tan −1  
 R (u , v ) 

Power Spectrum: E (u , v) = R 2 (u , v ) + I 2 (u , v )

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Amplitude and Phase
29

F (x)

amplitude

phase

original
F (x)
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Images and their spectrums
30

Image domain Frequency domain Image domain Frequency domain

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Properties of 2-D Fourier Transform
31

• Separability
• Linearity
• Scaling
• Shift Theorem
• Rotation
• Periodicity and conjugation
• Convolution
• Correlation
• Average

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Separability
32

❑ The implementation steps for the two-dimensional DFT


may be visualized as shown in the diagram below

Row Column
Transforms Transforms

f(x,y) F(x,v) F(u,v)


Multiply by N

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Separability (contd. )
33

f(x,y) F(u,v)

f(x,y) F(x,v) F(u,v)

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Linearity
34

❑ DFT is a linear operator

F[ a f1(x,y)+b f2(x,y)] = aF1(u,v)+bF2(u,v)

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Linearity (contd..)
35

f1(x,y) f2(x,y) 2f1(x,y)+3f2(x,y)

F1(u,v) F2(u,v) Phase Spectrum (2F1(u,v)+3F2(u,v))

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Scaling
36

1 u v
f (ax, by ) ⎯⎯
⎯→ DFT
F , 
ab  a b 

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Scaling (contd..)
37

f(x,y) F(u,v)

f(2x,3y) F(u,v)
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Shift Theorem
38

f ( x − x0 , y − y0 ) F (u, v ) exp[ − j 2 (ux0 + vy0 ) / N ]

f ( x , y ) exp[ j 2 (u0 x + v0 y ) / N ] F ( u − u0 , v − v 0 )

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Shift Theorem (contd..)
39

Original Image Spectrum Image


Mesh Plot

Tx = 50, Ty =50 Spectrum Image


Mesh Plot
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Rotation
40

In polar coordinates, f (x,y) and F(u,v) can be represented by f(r,


θ) and F(w,φ) alternatively. Then
f (r, θ+ θ0) F(w,φ + θ0)

(a) a sample image (b) its spectrum (c) rotated image (d) resulting spectrum

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Periodicity and conjugation
41

Periodicity :
F(u,v) = F(u+aN,v+bN)
f (x,y) = f (x+aN,y+bN)

Where a, b = 0, ±1, ± 2,……

Conjugation:
F(u,v) = F*(-u,-v)
|F(u,v)| = |F(-u,-v)|

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Convolution
42

2-D convolution is defined as:


M −1 N −1
1
f e ( x, y )  g e ( x, y ) =
MN
 f
m =0 n =0
e (m, n) g e ( x − m, y − n)

Then: f(x, y)*g(x, y) F(u, v)G(u, v)

f(x, y)g(x, y)F(u, v)*G(u, v)

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Convolution (contd..)
43

Original image Spectrum

Convolved image(convolved with mean filter) Spectrum


Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Correlation
44

2-D correlation is defined as:


M −1 N −1
1
f e ( x, y)  ge ( x, y) =
MN
  e (m, n) ge ( x + m, y + n)
f *

m= 0 n = 0

Correlation Theorems:
f ( x , y )  g ( x , y )  F * ( u, v ) G ( u, v )

f ( x , y ) g ( x , y )  F ( u, v )  G ( u, v )
*

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Average
45

Average of 2D image f (x, y) is defined as:


_ N −1 N −1
1
f ( x, y) = 2
N
  f ( x, y)
x =0 y =0

Let u=v=0 , then:


N −1 N −1
1
F (0,0) =
N
  f ( x, y)
x =0 y =0

_
1
f ( x, y) = F (0,0)
N
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..

< < image

and its
spectrum

46
Fast Fourier Transform
47

recursive algorithm

• decimation in time = odd even in freq. domain


• decimation in freq. domain = odd even in time

N → N log N
4 2

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Visualizing the DFT
48

 Consider the power spectrum of the 1D square wave


350

300

250

200

150

100

50

0
0 1 2 3 4 5 6 7

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Visualizing the DFT(circular shifting)
49

 The FT is centered about the origin


 But the DFT is centered about N/2
 We need to correct with a circular shift operation
 Or, multiply by (-1)k prior to taking the transform
350

300

250

200

150

100

50

0
0 1 2 3 4 5 6 7

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
DFT basis images
50
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Example
58

img=imread('lena.bmp','bmp');
subplot(121);imshow(img);
title('original image ')
fimg=fftshift(fft2(img));
subplot(122); imshow(abs(fimg)/10000)
title(' transformed image ')
original image transformed image

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Discrete Cosine Transform (DCT)
59
❑ DCT expresses a sequence of finite data points in
terms of a sum of cosine functions oscillating at
different frequencies.
❑ These cosine functions are treated as its basis
function.
❑ Fast algorithm exists.
❑ Most popular in image compression application
because of its energy compaction property.
❑ Adopted in JPEG.
❑ The periodicity implied by DCT implies that it
causes less blocking effect than DFT.
❑ Can be implemented by 2n points FFT.
Contd..
60

Transform kernel of two-dimensional DCT is

 (2 x + 1)u   (2 y + 1)v 
C ( x, y, u, v) =  (u )  (v)  cos    cos  2N 
 2N   

where
1 2
 (0) = ,  (i) = , 1  i  N
N N
Clearly, the kernel for the DCT is both separable and
symmetric, and hence the DCT may be implemented as a
series of one dimensional DCTs.

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
61

Forward transform
N −1 N −1
  (2 x + 1)u    (2 y + 1)v 
F (u, v) =  (u ) (v) f ( x, y) cos  cos 
x =0 y =0  2N   2N 

Inverse Transform
N −1 N −1
  (2 x + 1)u    (2 y + 1)v 
f ( x, y) =   (u ) (v) F (u, v) cos  cos 
u =0 v =0  2 N   2 N 
where u, v, x, y = 0, 1, 2, …, N-1
Forward and inverse transformations are same
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
62

 clc;
 clear
 N=8
 x=(0:N-1)';
 C=cos((2*x+1)*x'*pi/(2*N))*sqrt(2/N);
 C(:,1)=C(:,1)/sqrt(2);

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Kernel matrix to generate DCT
63
Basis Images
0.353553 0.490393 0.46194 0.415735 0.353553 0.277785 0.191342 0.097545

0.353553 0.415735 0.191342 -0.09755 -0.35355 -0.49039 -0.46194 -0.27779

0.353553 0.277785 -0.19134 -0.49039 -0.35355 0.097545 0.46194 0.415735

0.353553 0.097545 -0.46194 -0.27779 0.353553 0.415735 -0.19134 -0.49039

0.353553 -0.09755 -0.46194 0.277785 0.353553 -0.41573 -0.19134 0.490393

0.353553 -0.27779 -0.19134 0.490393 -0.35355 -0.09755 0.46194 -0.41573

0.353553 -0.41573 0.191342 0.097545 -0.35355 0.490393 -0.46194 0.277785

0.353553 -0.49039 0.46194 -0.41573 0.353553 -0.27779 0.191342 -0.09755

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Basis images of an 8x8 DCT
64

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Properties of DCT
65

Separability
2D DCT/ IDCT expression shows that they are separable.
So they can be implemented as two 1-D DCT/IDCT
Fast DCT
FDCT is possible in the same manner as FFT
Periodicity
Magnitude of DCT coefficient is periodic with period 2N
Example
66

Original Image DCT Coefficients

DCT Coefficients
(Zoomed) Mesh Plot
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Image Reconstruction in DCT
67

Original image Reconstructed image

Using only 1
DCT coefficient

Using 3 DCT
coefficients
Coefficients are selected
out of 8x8 window

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
68

Using 6 DCT Using 15 DCT


coefficients coefficients

Using 10 DCT Using 64 DCT


coefficients coefficients

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Karhunen-Loeve Transform
69

 K-L transform is a linear combination of orthogonal


functions of ensembles of input images.
 Basis functions are image dependent

 No fast algorithm exists

 Usually used for comparison

 Transform kernel is not fixed unlike other transforms

 Based on second order statistical properties of image

 Also called Hotelling transform or method of principal


components

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
 x1 
70
x 
 Covariance matrix of a population of vectors X =  2
: 


C x = E ( X −  x )( X −  x )
T
  
 xn 

M
1
x =
M
X
k =1
k

C x  real & symmetric

So, Orthogonal vectors of Cx can be calculated Ratnakar Dash,


Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
71

❑ Calculate eigenvectors and eigen values of Cx


❑ Sort eigen vectors depending on decreasing values of
eigen values
❑ Select some of the eigenvectors
❑ These eigenvectors are considered as transformed matrix
❑ Calculate the transformed images
Y = A( X −  x )

❑ Y is called as principal component coefficients.


❑This transformation is called K-L transform
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Properties of Y
72

y = 0
C y = AC x A T

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Example
73

Input matrix

  3  4  4  4  5  5  5  6 
x =          
  4  3  4  5  4  5  6  5 

Mean Vector
 4.5 
x = 



 4.5 

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
74

 0.75 0.375 
CX =
 0.375 
 0.75 

Compute Eigen values

(0.75 −  ) 2 = (0.375) 2
 0.75 −  = 0.375
  = 0.75  0.375
1 = 1.125
2 = 0.375
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..
75

We get two Eigen vectors


1 1
e = 
1
1
2  
1 
1 
e =
2  − 1

2  

Transform Matrix

→ A= 1 1 1 
1 − 1
2  
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd.
76

 Reconstructed
X = A Y + X
T

 K no of Eigen vectors
Y = Ak ( X −  X )
ˆ
X = A Y +
T
k X

Ak = k  n
Y = k 1
X = n 1 Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Properties of K-L Transform
77

 Decorrelation
 E[ y yH ]= E[ (UH x) (UH x)H ]= UH E[ x xH ] U = diag{1, 2, … , N}

 Note: Other matrices (unitary or nonunitary) may also


decorrelate the transformed sequence

 Minimizing MSE under basis restriction


 If only allow to keep m coefficients for any 1 m N, what’s
the best way to minimize reconstruction error?
→ Keep the coefficients w.r.t. the eigenvectors of the first m
largest Eigen values

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Principal Component Coefficients
78

Lena image Energy compaction in lena image

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Image Reconstruction in K-L Transform
79

1 PC 10 PCs 20 PCs

Original image
50 PCs All PCs

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Haar Wavelet Transform

 One dimensional transformation on each row followed by one


dimensional transformation of each column.

 Extracted coefficients would be


 Approximation
 Vertical
 Horizontal
 Diagonal

 Approximation coefficients are further decomposed into the next level

 4 level decomposition is used

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..

Graphical Representation - Wavelet decomposition


(level = 2)

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Approach

 For a 2X2 matrix

a b a + b a − b
x =   x =  
c d  c + d c − d 

1 a +b+c + d a −b +c −d 
y=  
2 a +b−c −d a −b−c + d 

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Example

2 2 9 5 4 14 0 4
2 0 5 2 Column wise Summation 2 7 2 3
6 7 4 7 13 11 -1 -3
3 4 8 8 7 16 -1 0

Row wise Summation

Approximation Horizontal

3 10.5 1 3.5 6 21 2 7
Finding Average
10 13.5 -1 -1.5 20 27 -2 -3
1 3.5 -1 0.5 2 7 -2 1
3 -2.5 0 -1.5 6 -5 0 -3
Vertical Diagonal
Properties of Haar transform
84

 The Haar transform is real and orthogonal. Therefore,


Hr=Hr*

 The Haar transform is a very fast transform.

 On an Nx1 vector it can be implemented in O(N) operations

 The Haar transform has poor energy compaction for Images

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
85

 %Initialization
 H=[1]; NC=1/sqrt(2);%normalization constant
LP=[1 1]; HP=[1 -1]; % iteration from H=[1]
 for i=1:Level
H=NC*[kron(H,LP);kron(eye(size(H)),HP)];
 end
 HaarTransformationMatrix=H;

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
86

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Basis images of Haar Transform
87

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
1-step Haar Decomposition
88

Original image Haar transformed image

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
2-step Haar Decomposition
89

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Discrete Walsh Transform (1-D)

n −1 bi ( x ) bn−1−i ( u )
1
g ( x, u ) =  (−1)
 N =0
i 

1− D Forward Kernel

where,
N → No. of Samples
n → No. of bits needed to represent x and u
b k ( z ) → k th bit in digital representation of z
N −1 n −1 bi ( x ) bn−1−i ( u )
1
W (u ) =  f ( x) (−1)
 N x =0
i =0

1− D Forward Transform Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..

n −1 bi ( x ) bn−1−i ( u )

h( x, u ) =  (−1)
=0 Difference
i  lies in
1− D Inverse Kernel Multiplicative
bi ( x ) bn−1−i ( u ) Factor
N −1 n −1
f ( x) =  W (u ) (−1)
x =0
 i =
 0


1− D Inverse Transform

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Discrete Walsh Transform (2-D)

n −1 {bi ( x ) bn−1−i ( u ) + bi ( y ) bn−1−i ( v )}


1
g ( x, y, u, v) =  (−1)
Ni =0


2 − D Forward Kernel

N −1 N −1 n −1 {bi ( x ) bn−1−i ( u ) + bi ( y ) bn−1−i ( v )}


1
W (u, v) =   f ( x, y ) (−1)
N y =0 x =0
i = 0

2 − D Forward Transform

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..

n −1 {bi ( x ) bn−1−i ( u ) + bi ( y ) bn−1−i ( v )}


1
h( x, y, u, v) =  (−1)
Ni =0


2 − D Inverse Kernel

N −1 N −1 n −1 {bi ( x ) bn−1−i ( u ) + bi ( y ) bn−1−i ( v )}


1
f ( x, y ) =   W (u, v) (−1)
N y =0 x =0
i = 0

2 − D Inverse Transform

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Property

• Separable

1
W (u ) = [Weven (u ) + Wodd (u )]
2
1
W (u + M ) = [Weven (u ) − Wodd (u )]
2
where,
N
u = 0,1,..., − 1
2
N
M=
2

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Basis images of Walsh Transform
95

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Hadamard Transfrom

n−1

1 {bi ( x )bi (u ) +bi ( y )bi ( v )}


g ( x, y, u, v) = (−1) i=0
N  
2 D Forward Kernel
n−1

1 {bi ( x )bi (u ) +bi ( y )bi ( v )}


h( x, y, u, v) = (−1) i=0
N  
2 D Inverse Kernel

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Hadamard Matrix
n−1

1  bi ( x )bi (u )
g ( x, u ) = (−1) i=0
N   
Hadamard Matrix
u
0(0) 1(7) 2(3) 3(4) 4(1) 5(6) 6(2) 7(5)
0 + + + + + + + +
1 + - + - + - + - sign changes
are not
2 + + - - + + - -
ordered (shown
3 + - - + + - - + in backet)
x
4 + + + + - - - -
5 + - + - - + - +
6 + + - - - - + +
7 + - - + - + + - Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Hadamard transform
98

 Transform matrices can be recursively generated

1 1 
H2 =  
 1 −1 
H n = H n −1  H1
H 3 = H 2  H1 , H 2 = H1  H1

Note: Hadamard Coefficients need reordering to concentrate


energy

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Contd..

 N=2

1 1 
H2 =  
1 − 1

H N HN 
=
H −N 
H 2N
H N

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Ordered Hadamard Transformation
n −1

1  bi ( x ) pi ( u )
g ( x, u ) = (−1) i=0
N
where,
p0 (u ) = bn −1 (u )
p1 (u ) = bn −1 (u ) + bn − 2 (u ) bi (u) is changed to pi(u)

p2 (u ) = bn − 2 (u ) + bn −3 (u )
.
.
.
pn −1 (u ) =Image u ) + b0 (u )
b1 (Transforms Ratnakar Dash,
Assistant Professor, CSE dept. of NIT Rourkela
Contd..

N=8

0 1 2 3 4 5 6 7
0 + + + + + + + +
1 + + + + - - - -
2 + + - - - - + +
3 + + - - + + - -
x
4 + - - + + - - +
5 + - - + - + + -
6 + - + - - + - +
7 + - + - + - + -
Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Basis images of Hadamard Transform
102

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Properties of Hadamard Transform
103

 Unlike Other Transform, the elements of the basis vectors of


the Hadamard transform take only the binary values +1 , -1,
therefore well suited for DSP.
 Hadamard transform H is real, symmetric, and orthogonal
 Hadamard transform is a fast transform. The one dimensional
transform can be implemented in O(N log2 N) additions and
subtractions

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Similarity between Walsh and Hadamard Transform

104

 Basis images of Walsh and Hadamard transforms


are same.
 So Hadamard transform is also known as Walsh
transform or Hadamard-Walsh transform.

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Image Reconstruction
105

Original image Reconstructed image

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
Image Reconstruction
106

Original image Reconstructed image

Ratnakar Dash,
Image Transforms Assistant Professor, CSE dept. of NIT Rourkela
107

You might also like