Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
Lecture 6, Page 2
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
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
C D E
0 low
Spring 2010
N F (((k )) N ). 2
Spring 2010
Lecture 6, Page 5
n =0
N 1
1 f (n) exp( j 2 (k )n / N ) = N
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
Lecture 6, Page 6
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
f ( n) h( n)
Spring 2010
F (k ) H (k )
Lecture 6, Page 7
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
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
Lecture 6, Page 9
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
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
Convolution Theorem
f (m, n) h(m, n)
F (k , l ) H (k , l )
Spring 2010
Lecture 6, Page 12
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
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
A
F(k,l)
B D
D B
k Low Frequency High Frequency
C A
C
k
Spring 2010
Lecture 6, Page 15
G (k , l ) = log(1 + F (k , l ))
Spring 2010
Lecture 6, Page 16
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 *
e
Spring 2010
j 2kn / N
=e
j 2k ( n + N ) / N
=e
j 2 ( k + N ) n / N
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
Lecture 6, Page 18
*
DFT x
h(n)
Convolution
g(n) DFT
H(k)
Multiplication
G(k)
Lecture 6, Page 19
n He(k)
n Fe(k) He(k)
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
t = B 1f = Af
f and t form a transform pair
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
N 1
Spring 2010
Lecture 6, Page 23
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
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
= f f = t AA t = t t = t
H H H H
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
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
F (m, n) = T (k , l ) H k ,l (m, n)
k =0 l =0
M 1 N 1
Spring 2010
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
Norm of a Matrix
F =< F, F >= F (m, n)
m =0 n =0 M 1 N 1 2
1, if k = i, l = j = 0, otherwise
Lecture 6, Page 33
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
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
Spring 2010
Lecture 6, Page 37
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
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
T0, 0
T2,3
Spring 2010
Lecture 6, Page 40
Spring 2010
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
Lecture 6, Page 43
DCT
t ( k ) = h ( n) f ( n) = ( k )
n =0 * k n =0 N 1 N 1
N 1
N 1
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
Designing D i i criteria it i
Signal de-correlation capability (Uncorrelated
components can be processed / analyzed more efficiently)
Error energy : EK = eK = t 2 (k )
k =K
N 1
Spring 2010
Lecture 6, Page 46
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
1 L N 1 ]
11
0 0 L N 1 N 1 ] = M 0
1
M 0
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
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
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
Lecture 6, Page 51
Example
Spring 2010
Lecture 6, Page 52
Example
Spring 2010
Lecture 6, Page 53
30
40
10
20
50
30
60 10 20 30 40 50 60
40
50
IDFT
10 20 30 40 50 60
60
Spring 2010
Lecture 6, Page 54
Spring 2010
Lecture 6, Page 55
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
FW (a, b) =
Spring 2010
f ( x)
a ,b
( x) dx
Frequenc cy
Time
ELEN E4830 Digital Image Processing Lecture 6, Page 58
H0: Lowpass filter, y0: approximation of x H1: Highpass filter, filter y1: details in x
Spring 2010
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
Columns H0 H1 H0 H1 2 2 2 2
N/2xN/2 LL LH HL HH
H1
Spring 2010
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
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
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