Lecture 6.
DFT Domain Image Filtering g
ELEN E4830 Digital Image Processing S i 2010 Spring
Zhu Liu
[email protected] li @ h tt AT&T Labs - Research David Gibbon d @
[email protected] h tt AT&T Labs - Research
Note: Part of the materials in the slides are from Gonzalezs Digital Image Processing and Prof. Yao Wangs lecture slides
Lecture Outline
1D/2D discrete Fourier transform (DFT) Fast Fo Fourier rier transform (FFT) 1D/2D unitary transform Discrete Cosine transform Karhunen Loeve transform Frequency domain filters Wavelet transform
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 2
Discrete Fourier Transform (DFT): g DTFT for Finite Duration Signals
If the signal is only defined for n = 0,1,..., N 1 : Fourier transform becomes : Fu(u) = f (n) exp( j 2un), u (0,1)
n =0 N 1
Sampling Fu(u) at u = k/N, k = 0 ,1,...,N-1, and rescaling yields : Forward transform (DFT) : 1 k 1 F (k ) = Fu( )= N N N Inverse transform (IDFT) : 1 f(n) = N
Spring 2010
f (n) exp( j 2kn / N ),
n =0
N 1
k = 0,1,..., N 1
F (k ) exp( j 2kn / N ),
k =0
N 1
n = 0,1,..., N 1
Lecture 6, Page 3
ELEN E4830 Digital Image Processing
Property of 1D DFT - Periodicity
F (k ) = F (((k )) N ), k < 0 or k N . where ((k )) N represents p modulo N .
1 N 1 F (k + mN ) = f (n) exp( j 2 (k + mN )n / N ) N n =0 1 N 1 = f (n) exp( j 2kn / N j 2mn) = F (k ) N n =0
A B C D E F G A F(k) B C D E N-1 N high low
Lecture 6, Page 4 ELEN E4830 Digital Image Processing
C D E
0 low
Spring 2010
Property of 1D DFT - Translation
f (((n no )) N ) F (k ) exp{ j 2 (kno / N )} F (((k k0 )) N ). f (n) exp{ j 2k0 n / N }
Special case
N is even, k0 = N/2.
f (n) exp{ jn} = f (n)(1)
N F (((k )) N ). 2
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 5
Property of 1D DFT - Symmetry
Conjugate symmetry for real sequences
F (k ) = F * (k ) = F * ( N k ) | F (k ) |=| F ( N k ) | or N N | F ( + k ) |=| F ( k ) |, | when N is even. 2 2
1 F * (k ) = N
n =0
N 1
1 f (n) exp( j 2 (k )n / N ) = N
f (n) exp( j 2kn / N ) = F (k )
n =0
N 1
F(k)
F(k)
0 1 2 3 4 5 6 7 N=8
Spring 2010
0 1 2 3 4 5 6 7 8 N=9
ELEN E4830 Digital Image Processing
Lecture 6, Page 6
Property of 1D DFT - Convolution
Circular convolution
f (n) h(n) = f (((n k )) N )h(k )
k =0 N 1
f(((n-k))N)
f(n)
h(n)
0 1 2 3 4
0 1 2 3 4
Convolution C l ti th theorem
n-1
n+2 n+4 n+1 n+3
f ( n) h( n)
Spring 2010
F (k ) H (k )
Lecture 6, Page 7
ELEN E4830 Digital Image Processing
2D Discrete Fourier Transform
Definition
Assuming f(m, n), m = 0, 1, , M M-1, 1, n = 0, 1, , N N-1, 1, is a finite length 2D sequence
F (k , l ) = f (m, n) = 1 MN 1 MN
M 1 N 1 m =0 n =0
f (m, n)e
M 1 N 1 k =0 l =0
j 2 (
km ln + ) M N
, k = 0,1,..., M 1, l = 0,1,..., N 1;
F (k , l )e
j 2 (
km ln + ) M N
, m = 0,1,..., M 1, n = 0,1,..., N 1.
Comparing to DTFT
F (u , v) =
m = n =
f (m, n)e
1/ 2 1 / 2 1 / 2
j 2 ( mu + nv )
k l , u= ,v = M N
f (m, n) =
Spring 2010
1/ 2
F (u , v)e j 2 ( mu + nv ) dudv
Lecture 6, Page 8
ELEN E4830 Digital Image Processing
Property of 2D DFT Periodicity
F (k , l ) = F (((k )) M , ((l )) N ), k < 0 or k M , l < 0 or l N .
-M
A
-M/2
B D B D
-N/2
A C
(0,0)
B D
(0,N-1)
C
0
Low Frequency
A
M/2
A C
B D
High Frequency
C
M k -N
Spring 2010
(M-1,0)
(M-1,N-1)
N/2
ELEN E4830 Digital Image Processing
Lecture 6, Page 9
Property of 2D DFT - Translation
f (((m m0 )) M , ((n n0 )) N ) F (k , l ) exp{ j 2 (km0 / M + ln0 / N )}, F (((k k0 )) M , ((l l0 )) N ).
F (((k M N )) M , ((l )) N ). ) 2 2
f (m, n) exp{ j 2 (k0 m / M + l0 n / N )}
f (m, n) exp{ { j (m + n)} = f (m, n)(1) ( m + n )
-M f(m,n) -M/2 0 F(k,l) M/2 M
Special Case: M,N=even, k0=M/2, l0=N/2
A C A C
-N
B D B D
-N/2 0
A C A C
B D B D
N/2 N
-M -M/2 0 M/2 M
D B D B
-N
C A C A
-N/2 0
D B D B
C A C A
N/2
Lecture 6, Page 10
f(m,n)(-1)(m+n)
F(k-M/2,l-N/2)
Spring 2010
ELEN E4830 Digital Image Processing
Property of 2D DFT - Symmetry
Conjugate symmetry for real sequences
F (k , l ) = F * (k ,l ) = F * ( M k , N l ), | F (k , l ) |=| F ( M k , N l ) |, M N M N | F ( + k , + l ) |=| F ( k , l ) |, | for M , N = even 2 2 2 2
0 0 5 1 6 2 7 3 8 4 3 2 1 9 33 32 31 1 6 2 7 3 8 4 4 3 2 1
M N 8 M=N=8=even, real
x x
9 40 39 38 37
10 11 12 13 14 36 35 34 33 15 16 17 18 19 32 31 30 29 20 21 22 23 24 28 27 26 25 20 25 26 27 28 24 23 22 21 15 29 30 31 32 19 18 17 15 10 33 34 35 36 14 13 12 11
10 11 12 13 14 30 29 28 15 16 17 18 19 27 26 25 20 21 22 23 24 23 22 21 15 25 26 27 19 18 17 16 10 28 29 30 14 13 12 11 5 31 32 33 9 Spring 2010 8 7 6
Conjugate pairs
M=N=9=odd
ELEN E4830 Digital Image Processing
5 37 38 39 40 9
Lecture 6, Page 11
Property of 2D DFT - Convolution
Circular Convolution
f (m, n) h(m, n) = f (((m k )) M , ((n l )) N )h(k , l )
k =0 l =0 M 1 N 1
Convolution Theorem
f (m, n) h(m, n)
F (k , l ) H (k , l )
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 12
Property of 2D DFT - Separability
Separability
2D DFT can be accomplished p by y N-point p 1D DFT of each row, , followed by M-point 1D DFT of each column
M 1 N 1 m =0 n =0 km ln + ) M N M 1
F (k , l ) =
1 MN
f (m, n)e
j 2 (
1 = M
1 N m=0
f (m, n)e
n =0
N 1
j 2
ln N
j 2 km M e
Separable Images
f (m, n) = f x (m) f y (n) F (k , l ) = Fx (k ) Fy (l )
Separability of 2D circular convolution (CC)
If h(m,n)=hx(m)hy(n), then 2D CC can be accomplished by Npoint 1D CC of each row, followed by M point 1D CC of each column column.
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 13
Computer Implementation of 2D DFT
1 F (k , l ) = f (m, n)e MN m =0 n =0 Complex array structure Implement complex multiplication and addition Pre-compute the constants
j 2 (
j2km/M for all k,m=0, e-j2 k m=0 1, 1 , M-1 M1 e-j2ln/N for all l,n=0, 1, , N-1.
M 1 N 1
km ln + ) M N
Use separable processing to speed up For real square image, only need to calculate ~half half of the points
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 14
Display of the Magnitude of 2D DFT
Shifting the low frequency components into the center
g (m, n) = f (m, n)(1) ( m + n ) G (k , l ) = F (((k M N )) M , ((l )) N ). 2 2
l G(k,l)
A
F(k,l)
B D
D B
k Low Frequency High Frequency
C A
C
k
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 15
Display of the Magnitude of 2D DFT
Amplitude rescaling
G (k , l ) = log(1 + F (k , l ))
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 16
Fast Fourier Transform (FFT)
Direct computation of N-point DFT takes N2 operations F (k ) = 1 N 1 f (n) exp( ( j 2kn k / N ), k = 0,..., N 1
N
n =0
FFT is a fast algorithm for computing DFT DFT, reducing the computation from N2 to N log2(N)
j 2kn / N e Complex p conjugate j g symmetry y y of
j 2k ( N n ) / N
=e
j 2kn / N
=e
j 2k ( n ) / N
= e
j 2kn / N *
Periodicity in n and k of e j 2kn / N
e
Spring 2010
j 2kn / N
=e
j 2k ( n + N ) / N
=e
j 2 ( k + N ) n / N
Matlab function for N N-point point DFT: fft(A,N) fft(A N)
ELEN E4830 Digital Image Processing Lecture 6, Page 17
Computation of 2D DFT
2D (MxN) point DFT can be computed in a separable manner:
First compute N-point FFT for each row M N log2 (N) Then compute M-point FFT for each column N M log2 (M) Total computation M N (log2 (N)+ log2 (M)) If M=N: 2N2log2 (N)
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 18
Calculate Linear Convolution Using DFT 1D DFT
f(n) is length N1, h(n) is length N2 g(n) = f(n)*h(h) is length N = N1+N2-1. To T use DFT, DFT need d to t extend t d f(n) f( ) and d h(n) h( ) t to length N by zero padding.
f(n) DFT F(k)
Spring 2010
*
DFT x
h(n)
Convolution
g(n) DFT
H(k)
Multiplication
G(k)
Lecture 6, Page 19
ELEN E4830 Digital Image Processing
Calculate Linear Convolution Using DFT
f(n), N1=5 fe(n), N=8 Fe(k)
n h(n), N2=4 he(n), N=8
n He(k)
n Fe(k) He(k)
f (n) * h(n) = f e (n) he (n)
n
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 20
Comparison of Complexity
f(n) is length N1, h(n) is length N2 , g(n) is length N 1 N=N N N1+N N2-1 1
g ( n) = f ( n) h( n) =
f (((n k ))
k =0
) h( k )
Direct calculation
Each point, N2 multiplications Overall, , N2 * N O(N ( 2)
Via FFT
N-point FFT for f(n) and h(n) N multiplications in the DFT domain N-point inverse FFT for F(k)*H(k) Overall, 3NlogN + N O(NlogN)
ELEN E4830 Digital Image Processing Lecture 6, Page 21
Spring 2010
One Dimensional Unitary Transform
Let CN represent the N dimensional complex space. Let h0, h1, , hN-1 represent N linearly independent p vectors in CN. For any vector f CN,
f = t (k )h k = Bt ,
k =0 N 1
t ( 0) t (1) . where B = [h 0 , h1 ,..., h N 1 ], t = M t ( N 1 )
Spring 2010
t = B 1f = Af
f and t form a transform pair
ELEN E4830 Digital Image Processing
Lecture 6, Page 22
Inner Product
Definition of inner product
< f1 , f 2 >= f1 f 2 = f1 (n) f 2 (n)
H * n =0 N 1
Orthogonal
< f1 , f 2 >= 0
Norm of a vector
f
2
=< f , f >= f H f = | f (n) |2
n =0
N 1
2 Normalized: unit norm f =1 Orthonomal = orthogonal + normalized
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 23
Orthonormal Basis Vector (OBV)
{hk, k=0,N-1} are OBV if Projection of f to hl
< h l , f >=< h l , t (k )h k >= t (k ) < h l , h k >= t (l ) = h l f
H k =0 k =0 N 1 N 1
1 k = l < h k , h l >= k ,l = 0 k l
h0 H H h1 t= f = B H f = Af M H h N 1
B is unitary y
Spring 2010
B 1 = B H , or B H B = BB H = I.
ELEN E4830 Digital Image Processing Lecture 6, Page 24
Definition of Unitary Transform
Forward transform t (k ) =< h , f >= h (n) f (n),
N 1 n =0 * k k H h0 H h1 f = Af t= M H h N 1
Inverse transform
f (n) = t (k )hk (n),
k =0 N 1
f = t (k )h k =[h 0
k =0
N 1
h1 L h N 1 ]t = A H t
ELEN E4830 Digital Image Processing Lecture 6, Page 25
Spring 2010
Example of 1D Unitary Transform
1 / 2 1/ 2 1/ 2 1/ 2 1 / 2 1/ 2 1 / 2 1 / 2 , h 2 = , h 3 = , h 0 = , h1 = 1 / 2 1 / 2 1 / 2 1/ 2 1 / 2 1 / 2 1/ 2 1 / 2 t 0 = 1 1 / 2 + 2 1 / 2 + 3 1 / 2 + 4 1 / 2 = 5 1 t = 1 1 / 2 + 2 1 / 2 3 1 / 2 4 1 / 2 = 2 2 1 f= 3 t 2 = 1 1 / 2 2 1 / 2 3 1 / 2 + 4 1 / 2 = 0 4 t3 = 1 1 / 2 2 1 / 2 + 3 1 / 2 4 1 / 2 = 1
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 26
Property of Unitary Transform
Energy preservation: ||f||=||t||.
Proof:
= f f = t AA t = t t = t
H H H H
Mean vector relation:
t = A f , f = A H t , where h f = E{f }, and t = E{t}
Covariance relation:
Ct = AC f A H , C f = A H Ct A, where C f = E{(f f )(f f ) H }, Ct = E{(t t )(t t ) H }
Proof:
t t = A(f f ) Ct = E{A(f f )(f f ) H A H } = AC f A H .
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 27
1D DFT as a Unitary Transform
1 F (k ) = N 1 f ( n) = N
f ( n )e
n =0
N 1
j 2
kn N
, k = 0, 1, ..., N 1;
F ( k )e
k =0
N 1
j 2
kn N
, n = 0, 1, ..., N 1.
1 j 2 N hk (n) = e , or N 1 k j 2 N e hk = , k = 0,1,..., N 1. M j 2 ( N 1) k N e
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 28
kn
Example: 1D DFT
N = 2 case : there are only two basis vectors : k exp( j 2 0) 1 1 1 1 1 2 hk = : h0 = 1, h1 = k 2 exp( j 2 1) 2 2 1 2 1 if f = , determine t0 , t1 2 Using t k =< < h k , f >, we obtain t0 = 1 3 1 1 1 1 1 1 1 1 , = ( ) ( ) + = = = = t 1 * 1 1 * 2 , , 1 * 1 1 * 2 1 1 2 1 2 2 2 2 2 2 2 3 1 1 1 1 Verify : t0h 0 + t1h1 = = = f 2 1 2 1 2
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 29
Another Example: 1D DFT
k exp( 2 0) j 4 1 1 1 1 k 1 j 1 j exp( j 2 1) 1 1 1 1 1 4 yields : h = ; h = ; h = ; h = N = 4 case : using h k = 0 1 2 3 2 1 2 1 2 exp( j 2 k 2) 2 1 21 4 1 1 j j k p( j 2 3) exp( 4 2 1 1 1 4 t0 = (2 + 4 + 5 + 3) = 7; t1 = (2 4 j 5 + 3 j ) = (3 + j ); 2 2 2 f = 1 1 1 5 ( ) ( ) (3 j ). t t j j 2 4 5 3 0 ; 2 4 5 3 = + = = + = 2 3 2 2 2 3 14 (3 + j ) (3 j ) 8 1 14 (3 + j ) j + (3 j ) j 1 16 =f Verify : t0h 0 + t1h1 + t 2h 2 + t3h 3 = = 4 14 + (3 + j ) + (3 j ) 4 20 14 + (3 + j ) j (3 j ) j 12
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 30
Two Dimensional Decomposition
Decompose a MxN 2D matrix F=[F(m,n)] into a linear combination of some basic images, Hk,l=[Hk,l(m,n)], so that:
F = T (k , l )H k ,l ,
k =0 l =0 M 1 N 1
F (m, n) = T (k , l ) H k ,l (m, n)
k =0 l =0
M 1 N 1
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 31
Graphical Interpretation
t1
+
t2 t3 t4
Inverse transform: Represent a vector (e.g. a block of image samples) as the superposition of some basis vectors (block patterns) Forward transform: Determine the coefficients associated with each basis vector
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 32
Two Dimensional Inner Product
Inner Product
< F1 , F2 >= F1* (m, n) F2 (m, n)
m =0 n =0 M 1 N 1
Norm of a Matrix
F =< F, F >= F (m, n)
m =0 n =0 M 1 N 1 2
Orthonormal of a set of basis images {Hk,l, k=0,1,,M-1, , , , , l=0,1,,N-1} , , , }
< H k ,l , H i , j > k ,i l , j
Spring 2010
1, if k = i, l = j = 0, otherwise
Lecture 6, Page 33
ELEN E4830 Digital Image Processing
Two Dimensional Unitary Transform
{Hk,l} is an orthonormal set of basis images Forward For ard transform
* T (k , l ) =< H k ,l , F >= H k ,l ( m, n) F ( m, n) m =0 n =0 M 1 N 1
Inverse transform
F (m, n) = T (k , l ) H k ,l (m, n), or
k =0 l =0 M 1 N 1 M 1 N 1 k =0 l =0
F = T (k , l )H k ,l
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 34
Example of 2D Unitary Transform
1/ 2 1 / 2 1 / 2 1/ 2 H 00 = , H 01 = , 1 / 2 1 / 2 1 / 2 1 / 2 1 / 2 1 / 2 1 / 2 1 / 2 H10 = , H11 = , 1 / 2 1 / 2 1 / 2 1 / 2 T (0,0) = 5 1 2 T (0,1) = 2 F= 3 4 T (1,0) = 1 T (1,1) = 0
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 35
2D DFT as a Unitary Transform
f (m, n) = 1 MN
M 1 N 1 k =0 l =0
F (k , l )e
km ln
j 2 (
km ln + ) M N
, m = 0,1,..., M 1, n = 0,1,..., N 1.
H k ,l (m, n) =
j 2 + 1 M N e MN
Basis Images for 8x8 DFT (Real Part)
Spring 2010
Basis Images for 8x8 DFT (Imaginary Part)
Lecture 6, Page 36
ELEN E4830 Digital Image Processing
Separable Unitary Transform
Let hk, k=0, 1, , M-1 represent orthonormal basis vectors in CM, Let gl, l=0, 1, , N-1 represent orthonormal basis vectors in CN, Hk,l=hkglT, or Hk,l(m,n)=hk(m)gl(n). Then Hk,l will form an orthonormal basis set in CMxN.
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 37
Example of Separable Unitary Transform Example 1
1 / 2 1/ 2 h0 = , h = . 1 1 / 2 1 / 2 1 / 2 1 / 2 1 / 2 1 / 2 T H 00 = h 0hT = H = h h = 0 01 0 1 1 / 2 1 / 2 1 / 2 1 / 2 1/ 2 1/ 2 1 / 2 1 / 2 T H10 = h1hT = H h h = = 0 11 1 1 1 / 2 1 / 2 1 / 2 1 / 2
2D DFT
H k ,l (m, n) =
+ j 2 1 M N , e MN ln
km ln
1 j 2 km 1 j 2 N M , g l ( n) = hk (m) = e e M N
Spring 2010 ELEN E4830 Digital Image Processing
Lecture 6, Page 38
Example: 4x4 DFT
1 1 1 1 1 1 1 j 1 1 1 j Recall the 1D DFT basis are : h 0 = ; h1 = ; h2 = ; h3 = 2 1 2 1 21 2 1 1 j 1 j
T
using H k,l = h k (h l ) yields : 1 1 1 1 1 1 1 1 1 H 0,0 = , 4 1 1 1 1 1 1 1 1 1 1 1 j j 1 j H1, 0 = 4 1 1 1 j j j 1 1 1 1 1 1 1 2,0 = 41 1 1 1 1 1 1 1 1 1 j j j H 3, 0 = 4 1 1 1 j j j Spring2010
1 j 1 j 1 1 1 1 1 j 1 j 1 1 j 1 j 1 1 1 1 1 1 1 j 1 j H 0,1 = , H 0, 2 = , H 0,3 = 4 1 j 1 j 4 1 1 1 1 4 1 j 1 j 1 j 1 j 1 1 1 1 1 j 1 j j 1 j j 1 1 1 1 1 1 1 j 1 1 j 1 j j j , H1,1 = 1 j 1 j 1 , H1, 2 = 1 j j , H1,3 = 1 j 1 j j 1 j 4 1 j 1 4 1 1 1 1 4 1 j j 1 j j j j 1 j 1 j j 1 j 1 j 1 1 1 1 1 1 1 j 1 j 1 j 1 j , H 2,1 = 1 1 j 1 , H 2, 2 = 1 1 1 1 1 , H 2 ,3 = 1 1 j 1 j 1 j 41 4 1 1 1 1 4 1 j 1 j j 1 j 1 1 j 1 1 1 1 1 1 j 1 j 1 j j 1 1 1 1 1 1 j 1 j 1 j j j j 1 j , H 3,1 = 1 j 1 , H 3, 2 = 1 j , H 3, 3 = 1 j 1 j j 1 1 j 4 1 j 1 4 1 4 1 1 1 1 j j 1 j 1 j j j j j 1 j 1 Lecture 6, Page 39 ELEN E4830 Digital Image Processing
Example: 4x4 DFT
1 2 2 0 0 1 3 1 , compute Tk ,l For F = 0 1 2 1 1 2 2 1 Using Tk ,l =< H k ,l , F > yields, e.g, 0 1 = 1 (1 + 2 + 2 + 0 + 0 + 1 + 3 + 1 + 0 + 1 + 2 + 1 + 1 + 2 + 2 1) = 18 1 2 1 4 4 2 2 1 1 1 1 1 * 1 2 2 0 j j 0 1 3 1 1 1 j j 1 =< H 2,3 , F >= , = (1 2 + 2 j + 3 j j + 1 2 + 1 j + 2 j 2 j j ) = (1 j ) 4 1 1 1 1 0 1 2 1 4 4 j j j j 1 2 2 1 1 1 1 1 0 1 1 1 , 1 1 1 0 1 1 1 1 2 2 1 3 1 1 1 =< H 0,0 , F >= 4 1 1
T0, 0
T2,3
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 40
Property of Separable Transform
When the transform is separable, we can perform the 2D transform separately separately.
First, do 1D transform for each row using basis vectors gl, Second, do 1D transform for each column of the intermediate image using basis vectors hk. Proof: M 1 N 1
* T (k , l ) = H k ,l ( m, n) F ( m, n) m =0 n =0 M 1 N 1 M 1 * * ( m ) g ( n ) F ( m , n ) = h (m)U (m, l ) = h* l k k m =0 n =0 m =0
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 41
Computational Savings of p Transform Separable A MxN transform takes about MxN calculations for each transform value, and the total number of calculation is (N4 if M=N) ) M2 N 2 ( If the transform is separable
1. Calculate M N-point p 1D transform, , each requiring N2 calculations 2. Calculate N M-point 1D transform, each requiring i i M2 calculations l l ti 3. Overall: MN2+NM2 (2N2, if M=N)
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 42
Other Transforms
Discrete cosine transform (DCT) Discrete sine transform (DST) Hadamard transform Haar transform Etc.
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 43
Discrete Cosine Transform (DCT)
The basis vectors for 1D N-point DCT
(2n + 1)k hk (n) = (k ) cos , with (k ) = 2N 2 N 1 N k =0 k = 1,..., N 1.
DCT
t ( k ) = h ( n) f ( n) = ( k )
n =0 * k n =0 N 1 N 1
N 1
N 1
(2n + 1)k f (n) cos( ) 2N
(2n + 1)k f (n) = hk (n)t (k ) = (k )t (k ) cos( ) 2N k =0 k =0
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 44
Hadamard Transform
Hm is a 2mx2m matrix, and it can be defined recursively
1 H m 1 Hm = 2 H m 1
H0 = 1
H m 1 H m 1
1 1 1 H1 = 2 1 1
1 1 1 1 1 1 1 1 1 H2 = 2 1 1 1 1 1 1 1 1
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 45
Constructing Signal Dependant Transform Bases Applications
Compression Feature selection
Designing D i i criteria it i
Signal de-correlation capability (Uncorrelated
components can be processed / analyzed more efficiently)
Energy compaction capability (Use the least number
p the original g signal g accurately) y) of coefficients to represent
= t (k )h , the approximation error is e = f f = t (k )h , f k k K K K
k =0 k =K K 1 N 1
Error energy : EK = eK = t 2 (k )
k =K
N 1
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 46
Karhunen Loeve Transform (KLT)
For a signal with covariance matrix Cf
KLT de-correlates de correlates the signal KLT achieves the minimal approximation error
Construction C t ti of f KLT
Let k and k the k-th eigenvalue and normalized li d eigenvector i t of f Cf, then th C f k = k k , with < k , l >= k ,l . Transform matrix of KLT is A H = = [ 0 1 L N 1 ]
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 47
Proof of KLT Properties
Diagonalize Cf.
H 0 H Ct = H C f = 1 C f [ 0 M H N 1 H 0 H 1 [ = M 0 0 H N 1
1 L N 1 ]
11
0 0 L N 1 N 1 ] = M 0
1
M 0
Minimize approximation error
0 0 O M L N 1 L L
Selecting the K coefficients associated with the K basis vectors that have the largest eigenvalues.
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 48
Filtering in the Frequency Domain
Relation between spatial and frequency domain operation:
g ( x, y ) = h( x, y ) f ( x, y ) G (u , v) = H (u , v) F (u , v) h( x, y ) = IDFT ( H (u , v)), )) H (u , v) = DFT (h( x, y )). ))
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 49
Low-Pass Filter Using DFT Window
Filtering in DFT domain:
G(k,l) G(k,l)=H(k,l) H(k,l) F(k,l)
Ideal Low-Pass Filter
H(k,l)= ( , ) 1 in low o frequency eque cy range a ge (t (the e four ou co corners!) es) = 0 in high frequency range Can think of H(k,l) as a mask in the DFT domain
The (k,l)th coefficient is unchanged if H(k,l)=1, and is set to zero if H(k,l)=0.
More generally generally, H(k H(k,l) l) can take on higher values in low-frequency range, and lower values in high frequency q y range g
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 50
Low-Pass Filter in DFT Domain
The window size where H(k l)=1 is H(k,l)=1 (2 W1+1)x(2 W2+1)
The window can be implemented in matlab via
R1=zeros(M,1); R1(1:W1+1,M-W1+1:M)=1; R2=zeros(N,1); ( , ); R2(1:W2+1,N-W2+1:N)=1; H=R1*R2;
Before shifting
Given G(k,l)=F(k,l)H(k,l), matlab may make small numerical errors in the inverse transform leading to complex valued images. g(m,n) is best reconstructed via:
g=real(ifft2(F.*H));
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 51
Example
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 52
Example
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 53
Spatial Filter Corresponding to Ideal LPF
10 20
30
40
10
20
50
30
60 10 20 30 40 50 60
40
50
IDFT
10 20 30 40 50 60
60
Ideal LPF with W1=W2=10
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 54
High Pass Filtering
The high-pass filtered image can be thought of as the original image minus the low pass filtered image.
High-pass High pass filtering by DFT windows:
If w(k,l) is a low-pass DFT window, simply define a high-pass g p window h(k, , l) by y h(k, , l) = 1 w(k, ( , l). )
High-pass filtering in spatial domain:
If L is a low-pass p filter of size W, simply p y define a high pass filter H via H(m,n) = (m,n) - L(m,n).
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 55
High Pass Filtering in DFT Domain
Before shifting
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 56
Introduction to Wavelets
Fourier Transform analyzes the entire signal
Frequency y t f(t) ()
Short Time Fourier Transform (STFT) analyzes a small section of a signal using windowing
window Frequenc cy f(t) ()
Time
t
Spring 2010 ELEN E4830 Digital Image Processing
Time
Lecture 6, Page 57
Wavelets Analysis
Wavelets are obtained from the mother wavelet (t) by dilations and shifting
a is the scaling parameter b is the shifting parameter
t b 1 a ,b (t ) = ( ) a a
Haar wavelet
1 0 0.5 1 -1 1 t
1D Continuous wavelet transform (CWT)
FW (a, b) =
Spring 2010
f ( x)
a ,b
( x) dx
Frequenc cy
Time
ELEN E4830 Digital Image Processing Lecture 6, Page 58
Two Band Subband Decomposition
H0: Lowpass filter, y0: approximation of x H1: Highpass filter, filter y1: details in x
Spring 2010
Haar Transform 1 1 h0 = [1 1]; h1 = [1 1] 2 2
Lecture 11, Page 59
ELEN E4830 Digital Image Processing
Wavelet Transform = Subband Tree
N N/2 N/4 N/2J N/2J
The above structure can be applied to rows of an image first, and then columns, forming 2D wavelet decomposition
Spring 2010 ELEN E4830 Digital Image Processing Lecture 11, Page 60
2D Wavelet Transform for Images
2D wavelet transform is accomplished by applying the 1D decomposition along rows of an image first, and then columns.
Rows H0 Input pu Image (NxN) 2
Columns H0 H1 H0 H1 2 2 2 2
N/2xN/2 LL LH HL HH
H1
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 11, Page 61
Wavelet Decomposition
LL
HL
LH HH
Spring 2010
LL: low pass for both horizontal and vertical directions LH: low pass for horizontal direction, high pass in vertical direction HL: low pass for vertical direction, high pass in horizontal direction HH: high pass in both horizontal and vertical directions
ELEN E4830 Digital Image Processing Lecture 11, Page 62
Reading
R. Gonzalez, Digital Image Processing, Sections 4.4 4 4 4.8 4 8 (not including 4.5.4). 4 5 4) A. Jain, Fundamentals of Digital Image Processing Chapter 5. Processing, 5
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 63
Homework (1)
1. Find the NxN point DFT of the following 2D image f(m, n), 0 m, n N: a) f(m, n) = 1, n = 0; f(m, n) = 0; n 0. b) f(m, n) = 1, m = 0; f(m, n) = 0, m 0. c) f(m, n) = 1, m = n; f(m, n) = 0, otherwise. d) f(m, n) = 1, m = N 1- n; f(m, n) = 0, otherwise. From the result, what can you say about the relation between the directionality of an image with ith that of its DFT? 2. One can use the DFT algorithms to compute the linear convolution of an image F(m, n) with a filter H(m, n). Let the convolved image be denoted by Y(m, n). i) Suppose the image size is 256x256 and the filter size is 11x11: What is the required size of the DFT to obtain the convolution of these two? Explain the exact steps to obtain the convolution result. ii) Suppose we use a 256x256 point DFT algorithm for F(m F(m, n) and H(m H(m, n) n), and obtain Z(m, n) as follows: Z = IDFT (DFT(X)DFT(H)). The DFT and IDFT in the above equation are both 256x256 points. For what values of (m, n) does Z(m, n) equal Y(m, n) ?
Spring 2010
ELEN E4830 Digital Image Processing
Lecture 6, Page 64
Homework (2)
3. Perform DFT (using the fft2 function in Matlab) on several test images of your choice (sample images are available at the Matlab image toolbox directory. Display the magnitude of the DFT image with and without shifting (using shift) and logarithmic mapping, pp g to see the effect of shifting g and logarithmic g mapping. pp g Include the p printouts in your submission. Also, examine in which frequency range the DCT coefficients have large magnitudes and explain why. Note that you may want to work on a small portion of your image (say 256x256 or less), to save computation time. Note that if your image is an RGB image, you should convert it to a grayscale image using "rgb2gray" rgb2gray function and apply the above operations on the grayscale image only. If the original image is an index image, you should not apply DFT to the index image directly, rather you should derive the grayscale image from it, using the "ind2gray" function. 4. Write a program (in Matlab or C) which filters an image by zeroing out certain DFT coefficients The program consists of 3 steps: coefficients. 1) performing DFT (you can use the fft2" function in Matlab); 2) zeroing out the coefficients at certain frequencies (see below); 3) performing inverse DFT to get back a filtered image. Truncate or scale the image properly such that its range is between 0 and 255. For part 2, try the following two types of filters: (a) let F(k, l) = 0 for TN < k, l < (1 - T )N, T = 1/4, 1/8 (i.e., low-pass filtering); (b) let F (k, l) = 0 for 0 k, l TN and (1 - T)N k, l N -1, T=1/4, 1/8 (i.e., high pass filtering); Compare the original and processed images. Comment on the function of the two types of filters filters.
Spring 2010 ELEN E4830 Digital Image Processing Lecture 6, Page 65