Lecture 146 418
Lecture 146 418
Image Transforms
2
Y=AX
By
Dr. Banshidhar Majhi Image (NxN)
{YN}
Inverse
Transform
Image (NxN)
{XN}
X=A-1Y
Preprocessing
Filtering
Enhancement
Image Compression
Feature Extraction
Edge detection
Corner detection
1
02-Jun-11
if k = 1 then an (t ) is orthonormal
Highly correlated input elements Î quite uncorrelated output
coefficients
Covariance matrix E[( y – E(y) ) ( y – E(y) )*T ]
2
02-Jun-11
∞
Let the set of samples represented by {u(n): 0 ≤ n ≤ N-1}
x (t ) = ∑n = 0
c n a n ( t ), t 0 ≤ t < t 0 + T
is a vector of dimension N
∞
⇒ ∫ x (t)a m ( t ) dt = ∫ ∑ n = 0
c na n ( t ) a m ( t ) dt
= c 0 ∫ a 0 (t )a m ( t ) dt +
T we get another vector
c1 ∫ a1 (t )a ( t ) dt + ... +
T
m
v= Au
c m ∫
T
a m (t )a m ( t ) dt + ... Transformed vector
Transformation matrix
3
02-Jun-11
Contd.. Example
13 14
Contd.. Contd..
15 16
k =0 l =0
4
02-Jun-11
To Compute transform coefficient v(k , l ) where {ak (m), k = 0,1,..N − 1} are 1D orthonormal sets of basis vectors
N −1 N −1
{bl (n), l = 0,1,..N − 1}
v(k , l ) = ∑∑ ak ,l (m, n)u (m, n) 0 ≤ k , l ≤ N − 1 should be unitary matrices themselves i.e.
In most cases we choose A & B to be same A ≈ {a(k , m)} and B = {a (l , n)}
m =0 n =0
∗ ∗T
Let a denotes the kth column of A
k Then the transformation equation can be written as
Define the matrices N −1 N −1
v( k , l ) = ∑∑ ak ,l (m, n)u (m, n) ≈ U , Ak∗,l
Ak∗,Tl = (ak∗ al∗ )T m =0 n =0
N −1 N −1
u (m, n) = ∑∑ ak∗,l (m, n)v(k , l )
Define the inner product of two NxN matrices F and G k =0 l =0
N −1 N −1
⇒ U = u (m, n) = ∑∑ v(k , l ) Ak∗,l
N −1 N −1
F , G = ∑∑ f (m, n )g ∗ (m, n ) k =0 l =0
m =0 n = 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
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
5
02-Jun-11
Example Contd..
21 22
1 ⎛1 1⎞ ⎛1 2⎞
A= ⎜
2 ⎜⎝1
U = ⎜⎜
⎟
− 1⎟⎠
⎟
4 ⎟⎠
Inverse Transform gives
⎝3
1 ⎛1 1 ⎞ ⎛1 2 ⎞ ⎛1 1⎞
Transformed Image V = ⎜⎜ ⎟⎜ ⎟⎜ ⎟
2 ⎝1 − 1⎠⎟ ⎝⎜ 3 4 ⎠⎟ ⎝⎜1 − 1⎠⎟ 1 ⎛1 − 1⎞⎛ 5 − 1⎞⎛1 1⎞
A∗T VA∗ = ⎜⎜ ⎟⎜ ⎟⎜ ⎟
1⎛ 4
= ⎜⎜
6 ⎞⎛1
⎟⎜
1⎞
⎟ 2 ⎝1 − 1⎟⎠⎜⎝ − 2 0 ⎟⎠⎜⎝1 − 1⎟⎠
2 ⎝− 2 − 2 ⎟⎠⎜⎝1 − 1⎟⎠
⎛ 5 − 1⎞ 1 ⎛3 − 1⎞⎛1 − 1⎞ ⎛ 1 2⎞
= ⎜⎜ ⎟⎜ ⎟=⎜ ⎟
− 1⎟⎠⎜⎝1 − 1⎟⎠ ⎜⎝ 3 4 ⎟⎠
= ⎜⎜ ⎟
⎝− 2 0 ⎟⎠ 2 ⎝7
To get basis images, take outer product of the columns of A ∗T = U ⇒ Original Image
1⎛1⎞ 1 ⎛1 1⎞
A ∗
= ⎜⎜ ⎟⎟ (1 1 ) = ⎜⎜ ⎟
1 ⎟⎠
0,0
2 ⎝1⎠ 2 ⎝1
1 ⎛1 − 1⎞
A 0∗,1 = ⎜⎜ ⎟ = A1∗, 0
2 ⎝ 1 − 1 ⎟⎠
1 ⎛ 1 − 1⎞
A1∗,1 = ⎜⎜ ⎟
2 ⎝−1 1 ⎟⎠
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
6
02-Jun-11
Contd.. Contd..
27 28
In general, Transform kernel can be represented as: Let R(u,v), I(u,v) be real part and imaginary part of
2π 2π F(u,v)
−j − j (ux + vy )
wN = e N
wNux + vy = e N
Modulus: (
F (u , v) = R 2 (u , v ) + I 2 (u , v ) )12
7
02-Jun-11
F (x)
amplitude
phase
original
∠F (x)
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
• Convolution
• Correlation
• Average
8
02-Jun-11
1 ⎛u v⎞
f (ax, by ) ⎯DFT
⎯⎯→ F⎜ , ⎟
ab ⎝ a b ⎠
f1(x,y) f2(x,y) 2f1(x,y)+3f2(x,y) Phase Spectrum
9
02-Jun-11
f(x,y) F(u,v)
f ( x , y ) exp[ j 2π (u0 x + v 0 y ) / N ] F ( u − u0 , v − v 0 )
f(2x,3y) F(u,v)
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
(a) a sample image (b) its spectrum (c) rotated image (d) resulting spectrum
10
02-Jun-11
f (x,y) = f (x+aN,y+bN)
f e ( x, y ) ∗ g e ( x, y ) =
MN
∑∑ f
m =0 n =0
e (m, n) g e ( x − m, y − n)
f * ( x , y ) g ( x , y ) ⇔ F ( u , v ) D G ( u, v )
11
02-Jun-11
Average Contd..
45
300
200
50
N → N log N
4 2
0
0 1 2 3 4 5 6 7
12
02-Jun-11
200
150
100
50
0
0 1 2 3 4 5 6 7
13
02-Jun-11
Example-1 Example-2
53 54
img=imread('lena.bmp','bmp'); A=imread('lena.bmp','bmp');
subplot(121);imshow(img);
m = fft2(A);
title('original image ')
fimg=fftshift(fft2(img)); m = fftshift(m);
subplot(122); imshow(abs(fimg)/10000) subplot(2,2,1);imshow(A);
title(' transformed image ')
original image transformed image
title('Original Image');
subplot(2,2,3)
mm = log(1+abs(m));
mm = mm/max(max(mm))*255;
imshow(uint8(mm));
title('Modulus');
Contd.. Contd..
55 56 Original Image Reconstruction Image
subplot(2,2,4)
ma= angle(m);
ma = (ma-min(min(ma)))/(max(max(ma)) -
min(min(ma)) )*255;
imshow(uint8(ma));
title('Phase');
[i,j] = find(abs(m)==max(max(abs(m)))); Modulus Phase
m(i,j) = m(i,j)*2;
s = ifft2(m);
subplot(2,2,2)
imshow(uint8(abs(s)));
title('Reconstruction Image');
14
02-Jun-11
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
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
15
02-Jun-11
Separability
2D DCT/ IDCT expression shows that they are separable.
So they can be implemented as two 1-D DCT/IDCT
Fast DCT
Original Image DCT Coefficients
FDCT is possible in the same manner as FFT
Periodicity
Magnitude of DCT coefficient is periodic with period 2N
DCT Coefficients
(Zoomed) Mesh Plot
Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela
16
02-Jun-11
{ }
functions of ensembles of input images. ⎢ ⎥
C x = E ( X − μ x )( X − μ x ) ⎣ xn ⎦
T
Basis functions are image dependent
Contd.. Example
67 68
Y = A( X − μ x )
17
02-Jun-11
Contd.. Contd..
69 70
⎛ 0 . 75 0 . 375 ⎞
C X = ⎜⎜ ⎟⎟
⎝ 0 . 375 0 . 75 ⎠ We get two Eigen vectors
1 ⎛1 ⎞
Compute Eigen values e = ⎜⎜ ⎟⎟
1 1
2 ⎝ ⎠
( 0 . 75 − λ ) 2 = ( 0 . 375 ) 2
1 ⎛ 1 ⎞
⇒ 0 . 75 − λ = ± 0 . 375 e = ⎜⎜ ⎟⎟
2 − 1
2 ⎝ ⎠
⇒ λ = 0 . 75 ± 0 . 375
Transform Matrix
λ 1 = 1 . 125 ⎡1 1 ⎤
→ A = 1
λ 2 = 0 . 375 ⎢1 − 1 ⎥⎦
2 ⎣
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
Decorrelation
E[ y yH ]= E[ (UH x) (UH x)H ]= UH E[ x xH ] U = diag{λ1, λ2, … , λN}
18
02-Jun-11
Contd.. Approach
⎛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 ⎟⎠
19
02-Jun-11
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
Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela
20
02-Jun-11
g ( x, y ) = ∏ (−1)
N i =0
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 b ( x ) bn−1−i ( u )
1 N −1 i
W (u ) = ∑ f ( x)∏ (−1)
N x =0 i =0
Dr. Banshidhar Majhi, 1− D Forward Transform Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
21
02-Jun-11
Contd.. Property
⎛1 1 ⎞
H1 = ⎜⎜ ⎟⎟
⎝1 − 1⎠
H n = H n −1 ⊗ H1
H 3 = H1 ⊗ H 2 , H 2 = H1 ⊗ H1
"
Note: Hadamard Coefficients need reordering to concentrate
energy
22
02-Jun-11
n −1
⎡H HN ⎤ 1 + - + - + - + - sign changes
H 2N = ⎢ N are not
H − N ⎥⎦
2 + + - - + + - -
ordered (shown
⎣H N x
3 + - - + + - - + in backet)
4 + + + + - - - -
5 + - + - - + - +
6 + + - - - - + +
Dr. Banshidhar Majhi, 7 + - - + - + + - Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
23
02-Jun-11
1 ∑ bi ( x ) p i ( u ) N=8
g ( x, u ) = ( − 1) i = 0
N
u
where ,
0 1 2 3 4 5 6 7
p 1 ( u ) = b n −1 ( u ) + b n − 2 ( u ) bi (u) is changed to pi(u) 0 + + + + + + + +
p 2 (u ) = bn − 2 (u ) + bn − 3 (u ) 1 + + + + - - - -
2 + + - - - - + +
. 3 + + - - + + - -
x
. 4 + - - + + - - +
5 + - - + - + + -
. 6 + - + - - + - +
p n −1 ( u ) = b1 ( u ) + b 0 ( u ) 7 + - + - + - + -
Dr. Banshidhar Majhi, Dr. Banshidhar Majhi,
Image Transforms Professor, CSE dept. of NIT Rourkela Image Transforms Professor, CSE dept. of NIT Rourkela
95 96
Unlike Other Transform, the elements of the basis vectors of Basis images of Walsh and Hadamard transforms
the Hadamard transform take only the binary values +1 , -1, are same.
therefore well suited for DSP
Hadamard transform H is real, symmetric, and orthogonal So Hadamard transform is also known as Walsh
Hadamard transform is a fast transform. The one dimensional
transform or Hadamard-Walsh transform.
transform can be implemented in O(N log2 N) additions and
subtractions
24
02-Jun-11
99
25