Upcoming SlideShare
×

# Image trnsformations

5,679 views

Published on

Published in: Technology, Art & Photos
• Full Name
Comment goes here.

Are you sure you want to Yes No

Are you sure you want to  Yes  No

### Image trnsformations

1. 1. 1Chapter 4:Frequency Domain Processing Image TransformationsIUST
2. 2. 2Contents Fourier Transform and DFT Walsh Transform Hadamard Transform Walsh-Hadamard Transform (WHT) Discrete Cosine Transform (DCT) Haar Transform Slant Transform Comparison of various Transforms
3. 3. 3Introduction Although we discuss other transforms insome detail in this chapter, we emphasizethe Fourier transform because of its widerange of applications in image processingproblems.
4. 4. 4Fourier Transform (1-D)( ) ( ) [ ] ( )( ) ( )( )uXuXsinAXuFeuXsinuAdxux2jexpxfuF uXjππ=⇒ππ=π−= π−∞∞−∫
5. 5. 5Fourier Transform (2-D)( ) ( )[ ] ( ) ( )( )( )( )vYvYsinuXuXsinAXYv,uFdydxvyux2jexpy,xf)v,u(Fππππ=⇒+π−= ∫ ∫+∞∞−+∞∞−
6. 6. 6Discrete Fourier TransformIn the two-variable case the discrete Fourier transform pair is
7. 7. 7Discrete Fourier TransformWhen images are sampled in a squared array, i.e. M=N,we can write
8. 8. 8DiscreteFourierTransformExamplesAt all of theseexamples, the Fourierspectrum is shiftedfrom top left corner tothe center of thefrequency square.
9. 9. 9DiscreteFourierTransformExamplesAt all of theseexamples, the Fourierspectrum is shiftedfrom top left corner tothe center of thefrequency square.
10. 10. 10DiscreteFourierTransformDisplayAt all of theseexamples, the Fourierspectrum is shiftedfrom top left corner tothe center of thefrequency square.
11. 11. 11Discrete Fourier TransformExampleMain Image (Gray Level) DFT of Main image(Fourier spectrum)Logarithmic scaledof the Fourier spectrum
12. 12. 12Discrete Fourier Transform % Program written in Matlab for computing FFT of a given gray color image. % Clear the memory. clear; % Getting the name and extension of the image file from the user. name=input(Please write the name and address of the image : ,s); % Reading the image file into variable a. a=imread(name); % Computing the size of image. Assuming that image is squared. N=length(a); % Computing DFT of the image file by using fast Fourier algorithm. F=fft2(double(a))/N;MATLAB program page 1 from 3.
13. 13. 13Discrete Fourier Transform % Shifting the Fourier spectrum to the center of the frequency square. for i=1:N/2; for j=1:N/2 G(i+N/2,j+N/2)=F(i,j); end;end for i=N/2+1:N; for j=1:N/2 G(i-N/2,j+N/2)=F(i,j); end;end for i=1:N/2; for j=N/2+1:N G(i+N/2,j-N/2)=F(i,j); end;end for i=N/2+1:N; for j=N/2+1:N G(i-N/2,j-N/2)=F(i,j); end;endMATLAB program page 2 from 3.
14. 14. 14Discrete Fourier Transform % Computing and scaling the logarithmic Fourier spectrum. H=log(1+abs(G)); for i=1:N H(i,:)=H(i,:)*255/abs(max(H(i,:))); end % Changing the color map to gray scale (8 bits). colormap(gray(255)); % Showing the main image and its Fourier spectrum. subplot(2,2,1),image(a),title(Main image); subplot(2,2,2),image(abs(G)),title(Fourier spectrum); subplot(2,2,3),image(H),title(Logarithmic scaled Fourier spectrum);MATLAB program page 3 from 3.
15. 15. 15Discrete Fourier Transform(Properties) SeparabilityThe discrete Fourier transform pair can be expressed in the seperable forms:( ) [ ] ( ) [ ]( ) [ ] ( ) [ ]∑∑∑∑−=−=−=−=ππ=π−π−=1N0v1N0u1N0y1N0xN/vy2jexpv,uFN/ux2jexpN1y,xfN/vy2jexpy,xfN/ux2jexpN1v,uF
16. 16. 16Discrete Fourier Transform(Properties) Translation( ) ( )[ ] ( )( ) ( ) ( )[ ]N/vyux2jexpv,uFyy,xxfandvv,uuFN/yvxu2jexpy,xf00000000+π−⇔−−−−⇔+πThe translation properties of theFourier transform pair are :
17. 17. 17Discrete Fourier Transform(Properties) PeriodicityThe discrete Fourier transform and itsinverse are periodic with period N; that is,F(u,v)=F(u+N,v)=F(u,v+N)=F(u+N,v+N)If f(x,y) is real, the Fourier transform alsoexhibits conjugate symmetry:F(u,v)=F*(-u,-v)Or, more interestingly:|F(u,v)|=|F(-u,-v)|
18. 18. 18Discrete Fourier Transform(Properties) RotationIf we introduce the polar coordinatesϕω=ϕω=θ=θ=sinvcosusinrycosrxThen we can write:( ) ( )00 ,F,rf θ+φω⇔θ+θIn other words, rotating F(u,v)rotates f(x,y) by the same angle.
19. 19. 19Discrete Fourier Transform(Properties) ConvolutionThe convolution theorem intwo dimensions is expressedby the relations :( ) ( ) ( )( ) ( ) ( ) ( )v,uG*v,uFy,xgy,xfandv,uGv,uF)y,x(g*y,xf⇔⇔Note :( ) ( ) ( ) ( )∫ ∫∞∞−∞∞−βαβ−α−βα= ddy,xg,fy,xg*y,xf
20. 20. 20Discrete Fourier Transform(Properties) CorrelationThe correlation of two continuousfunctions f(x) and g(x) is definedby the relation( ) ( ) ( ) ( ) αα+α= ∫∞∞−dxgfxgxf *So we can write:( ) ( ) ( ) ( )( ) ( ) ( ) ( )v,uGv,uFy,xgy,xfandv,uGv,uFy,xgy,xf**⇔⇔
21. 21. 21DiscreteFourierTransform Sampling(Properties)1-DThe Fourier transform and the convolution theorem provide thetools for a deeper analytic study of sampling problem. In particular, wewant to look at the question of how many samples should be taken so thatno information is lost in the sampling process. Expressed differently, theproblem is one of the establishing the sampling conditions under which acontinuous image can be recovered fully from a set of sampled values. Webegin the analysis with the 1-D case.As a result, a function which is band-limited in frequency domainmust extend from negative infinity to positive infinity in time domain (or xdomain).
22. 22. 22DiscreteFourierTransform Sampling(Properties)1-Df(x) : a given functionF(u): Fourier Transform of f(x)which is band-limiteds(x) : sampling functionS(u): Fourier Transform of s(x)G(u): window for recovery ofthe main function F(u) and f(x).Recovered f(x) from sampled data
23. 23. 23DiscreteFourierTransform Sampling(Properties)1-Df(x) : a given functionF(u): Fourier Transform of f(x)which is band-limiteds(x) : sampling functionS(u): Fourier Transform of s(x)h(x): window for making f(x)finited in time.H(u): Fourier Transform of h(x)
24. 24. 24DiscreteFourierTransform Sampling(Properties)1-Ds(x)*f(x) (convolutionfunction) is periodic, withperiod 1/Δu. If N samples off(x) and F(u) are taken and thespacings between samples areselected so that a period ineach domain is covered by Nuniformly spaced samples,then NΔx=X in the x domainand NΔu=1/Δx in thefrequency domain.
25. 25. 25DiscreteFourierTransform Sampling(Properties)2-DThe sampling process for 2-Dfunctions can be formulatedmathematically by making useof the 2-D impulse functionδ(x,y), which is defined as( ) ( ) ( )0000 y,xfdydxyy,xxy,xf =−−δ∫ ∫∞∞−∞∞−A 2-D sampling function isconsisted of a train of impulsesseparated Δx units in the xdirection and Δy units in the ydirection as shown in the figure.
26. 26. 26DiscreteFourierTransform Sampling(Properties)2-DIf f(x,y) is band limited (that is, itsFourier transform vanishes outsidesome finite region R) the result ofcovolving S(u,v) and F(u,v) mightlook like the case in the caseshown in the figure. The functionshown is periodic in twodimensions.( )=01v,uG(u,v) inside one of the rectanglesenclosing RelsewhereThe inverse Fourier transform ofG(u,v)[S(u,v)*F(u,v)] yields f(x,y).
27. 27. 27The Fast Fourier Transform (FFT) Algorithm
28. 28. 28Other Seperable Image TransformsFor 2-D square arrays the forward and inverse transforms are( ) ( ) ( )( ) ( ) ( )∑∑∑∑−=−=−=−===1N0u1N0v1N0x1N0yv,u,y,xhv,uTy,xfandv,u,y,xgy,xfv,uT g(x,y,u,v) : forward transformation kernelh(x,y,u,v) : inverse transformation kernelThe forward kernel is said to be seperable ifg(x,y,u,v)=g1(x,u)g2(y,v)In addition, the kernel is symmetric if g1 is functionally equal to g2. In this casewe can write:g(x,y,u,v)=g1(x,u)g1(y,v)
29. 29. 29Other Seperable Image TransformsAFAT =BTBFABBAFABBTB1=⇒==−Where F is the N×N image matrix,A is an N×N symmetric transformation matrixT is the resulting N×N transform.If the kernel g(x,y,u,v) is seperable and symmetric,( ) ( ) ( )∑∑−=−==1N0x1N0yv,u,y,xgy,xfv,uTalso may be expressed in matrix form:And for inverse transform we have:
30. 30. 30Walsh TransformWhen N=2n, the 2-D forward and inverse Walsh kernels are given by the relations( ) ( ) ( ) ( ) ( ) ( )[ ]( ) ( ) ( ) ( ) ( ) ( )[ ]∏∏−=+−=+ −−−−−−−−−=−=1n0ivbybubxb1n0ivbybubxb i1nii1nii1nii1ni1N1v,u,y,xhand1N1v,u,y,xgWhere bk(z) is the kth bit in the binary representation of z.So the forward and inverse Walsh transforms are equal in form; that is:
31. 31. 31Walsh Transform“+” denotes for +1 and “-” denotes for -1.( ) ( ) ( ) ( )∏−=−−−=1n0iubxb i1ni1N1u,xgIn 1-D case we have :In the following table N=8 so n=3 (23=8).1-D kernel
32. 32. 32Walsh TransformThis figure shows the basis functions (kernels) asa function of u and v (excluding the 1/N constantterm) for computing the Walsh transform whenN=4. Each block corresponds to varying x and yform 0 to 3 (that is, 0 to N-1), while keeping uand v fixed at the values corresponding to thatblock. Thus each block consists of an array of4×4 binary elements (White means “+1” andBlack means “-1”). To use these basis functionsto compute the Walsh transform of an image ofsize 4×4 simply requires obtaining W(0,0) bymultiplying the image array point-by-point withthe 4×4 basis block corresponding to u=0 andv=0, adding the results, and dividing by 4, andcontinue for other values of u and v.
33. 33. 33Walsh TransformExampleMain Image (Gray Level) WT of Main image(Walsh spectrum)Logarithmic scaledof the Walsh spectrum
34. 34. 34Walsh Transform (WT) % Program written in Matlab for computing WT of a given gray color image. clear; % Getting the name and extension of the image file from the user. name=input(Please write the name and address of the image : ,s); a=imread(name); N=length(a); % Computing Walsh Transform of the image file. n=log2(N);n=1+fix(n);f=ones(N,N); for x=1:N; for u=1:N p=dec2bin(x-1,n); q=dec2bin(u-1,n); for i=1:n; f(x,u)=f(x,u)*((-1)^(p(n+1-i)*q(i))); end;end;end F=(1/N)*f*double(a)*f;MATLAB program page 1 from 3.
35. 35. 35Walsh Transform (WT) % Shifting the Fourier spectrum to the center of the frequency square. for i=1:N/2; for j=1:N/2 G(i+N/2,j+N/2)=F(i,j); end;end for i=N/2+1:N; for j=1:N/2 G(i-N/2,j+N/2)=F(i,j); end;end for i=1:N/2; for j=N/2+1:N G(i+N/2,j-N/2)=F(i,j); end;end for i=N/2+1:N; for j=N/2+1:N G(i-N/2,j-N/2)=F(i,j); end;endMATLAB program page 2 from 3.
36. 36. 36Walsh Transform (WT) % Computing and scaling the logarithmic Walsh spectrum. H=log(1+abs(G)); for i=1:N H(i,:)=H(i,:)*255/abs(max(H(i,:))); end % Changing the color map to gray scale (8 bits). colormap(gray(255)); % Showing the main image and its Walsh spectrum. subplot(2,2,1),image(a),title(Main image); subplot(2,2,2),image(abs(G)),title(Walsh spectrum); subplot(2,2,3),image(H),title(Logarithmic scaled Walsh spectrum);MATLAB program page 3 from 3.
37. 37. 37Hadamard TransformWhen N=2n, the 2-D forward and inverse Hadamard kernels are given by the relations( ) ( ) ( ) ( ) ( ) ( )[ ]( ) ( ) ( ) ( ) ( ) ( )[ ]∏∏−=+−=+−=−=1n0ivbybubxb1n0ivbybubxb iiiiiiii1N1v,u,y,xhand1N1v,u,y,xgWhere bk(z) is the kth bit in the binary representation of z.So the forward and inverse Hadamard transforms are equal in form; that is:
38. 38. 38Hadamard Transform( ) ( ) ( ) ( )∏−=−=1n0iubxb ii1N1u,xgIn 1-D case we have :In the following table N=8 so n=3 (23=8).1-D kernel“+” denotes for +1 and “-” denotes for -1.
39. 39. 39Hadamard TransformThis figure shows the basis functions(kernels) as a function of u and v (excludingthe 1/N constant term) for computing theHadamard transform when N=4. Each blockcorresponds to varying x and y form 0 to 3(that is, 0 to N-1), while keeping u and vfixed at the values corresponding to thatblock. Thus each block consists of an arrayof 4×4 binary elements (White means “+1”and Black means “-1”) like Walshtransform. If we compare these twotransforms we can see that they only differin the sense that the functions in Hadamardtransform are ordered in increasing sequencyand thus are more “natural” to interpret.
41. 41. 41Hadamard Transform (HT) % Program written in Matlab for computing HT of a given gray color image. clear; % Getting the name and extension of the image file from the user. name=input(Please write the name and address of the image : ,s); a=imread(name); N=length(a); % Computing Hadamard Transform of the image file. n=log2(N);n=1+fix(n);f=ones(N,N); for x=1:N; for u=1:N p=dec2bin(x-1,n); q=dec2bin(u-1,n); for i=1:n; f(x,u)=f(x,u)*((-1)^(p(n+1-i)*q(n+1-i))); end;end;end F=(1/N)*f*double(a)*f;MATLAB program page 1 from 3.
42. 42. 42Hadamard Transform (HT) % Shifting the Fourier spectrum to the center of the frequency square. for i=1:N/2; for j=1:N/2 G(i+N/2,j+N/2)=F(i,j); end;end for i=N/2+1:N; for j=1:N/2 G(i-N/2,j+N/2)=F(i,j); end;end for i=1:N/2; for j=N/2+1:N G(i+N/2,j-N/2)=F(i,j); end;end for i=N/2+1:N; for j=N/2+1:N G(i-N/2,j-N/2)=F(i,j); end;endMATLAB program page 2 from 3.
43. 43. 43Hadamard Transform (HT) % Computing and scaling the logarithmic Hadamard spectrum. H=log(1+abs(G)); for i=1:N H(i,:)=H(i,:)*255/abs(max(H(i,:))); end % Changing the color map to gray scale (8 bits). colormap(gray(255)); % Showing the main image and its Hadamard spectrum. subplot(2,2,1),image(a),title(Main image); subplot(2,2,2),image(abs(G)),title(Hadamard spectrum); subplot(2,2,3),image(H),title(Logarithmic scaled Hadamardspectrum);MATLAB program page 3 from 3.
45. 45. 451-D WHT Kernel Functions
46. 46. 462-D WHT Kernel Functions
47. 47. 47WHT and Fourier Transform
48. 48. 48WHT Example
49. 49. 49Discrete Cosine Transform
50. 50. 50Discrete Cosine Transform (DCT)Each block consistsof 4×4 elements,corresponding to xand y varying from 0to 3. The highestvalue is shown inwhite. Other valuesare shown in grays,with darker meaningsmaller.
51. 51. 51Discrete Cosine TransformExampleMain Image (Gray Level) DCT of Main image(Cosine spectrum)Logarithmic scaledof the Cosine spectrum
52. 52. 52Discrete Cosine Transform % Program written in Matlab for computing DCT of a given gray color image. % Clear the memory. clear; % Getting the name and extension of the image file from the user. name=input(Please write the name and address of the image : ,s); % Reading the image file into variable a. a=imread(name); % Computing the size of image. Assuming that image is squared. N=length(a); % Computing DCT of the image file. F=dct2(double(a));MATLAB program page 1 from 3.
53. 53. 53Discrete Cosine Transform % Shifting the Fourier spectrum to the center of the frequency square. for i=1:N/2; for j=1:N/2 G(i+N/2,j+N/2)=F(i,j); end;end for i=N/2+1:N; for j=1:N/2 G(i-N/2,j+N/2)=F(i,j); end;end for i=1:N/2; for j=N/2+1:N G(i+N/2,j-N/2)=F(i,j); end;end for i=N/2+1:N; for j=N/2+1:N G(i-N/2,j-N/2)=F(i,j); end;endMATLAB program page 2 from 3.
54. 54. 54Discrete Cosine Transform % Computing and scaling the logarithmic Cosine spectrum. H=log(1+abs(G)); for i=1:N H(i,:)=H(i,:)*255/abs(max(H(i,:))); end % Changing the color map to gray scale (8 bits). colormap(gray(255)); % Showing the main image and its Cosine spectrum. subplot(2,2,1),image(a),title(Main image); subplot(2,2,2),image(abs(G)),title(Cosine spectrum); subplot(2,2,3),image(H),title(Logarithmic scaled Cosine spectrum);MATLAB program page 3 from 3.
55. 55. 55DCT and Fourier Transform
56. 56. 56DCT Example
57. 57. 57Blockwise DCT Example
58. 58. 58Fast DCT Algorithm
59. 59. 59Fast DCT Algorithm
60. 60. 60Haar TransformThe Haar transform is based on the Haar functions, hk(z), which are defined over thecontinuous, closed interval [0,1] for z, and for k=0,1,2,…,N-1, where N=2n. The firststep in generating the Haar transform is to note that the integer k can be decomposeduniquely as k=2p+q-1where 0≤p≤n-1, q=0 or 1 for p=0, and 1≤q≤2pfor p≠0.With this background, the Haar functions are defined as( ) ( ) [ ]( ) ( )[ ]∈≤−−−≤−==∈==∆∆1,0zforotherwise02qz22/1q222/1qz21q2N1zhzhand1,0zforN1zhzhpp2/ppp2/p00k000
61. 61. 61Haar Transform Haar transform matrix for sizes N=2,4,8−=111121Hr2−−−−=201120110211021141Hr4−−−−−−−−−−−−=200020112000201102002011020020110020021100200211000202110002021181Hr8Can be computed by taking sums and differences.Fast algorithms by recursively applying Hr2.
62. 62. 62Haar Transform Example
63. 63. 63Haar Transform Example
64. 64. 64Haar TransformMATLAB program page 1 from 1.% Program written in Matlab for computing HT of a given gray color image.% Getting the name and extension of the image file from the user.name=input(Please write the name and address of the image : ,s);a=imread(name); N=length(a);% Computing Haar Transform of the image file.for i=1:N p=fix(log2(i)); q=i-(2^p);for j=1:N z=(j-1)/N;if (z>=(q-1)/(2^p))&&(z<(q-1/2)/2^p) f(i,j)=(1/(sqrt(N)))*(2^(p/2));elseif (z>=(q-1/2)/(2^p))&&(z<(q/2^p)) f(i,j)=(1/(sqrt(N)))*(-(2^(p/2)));else f(i,j)=0;end;end;endF=f*double(a)*f;% Changing the color map to gray scale (8 bits).colormap(gray(255));% Showing the main image and its Hadamard spectrum.subplot(2,2,1),image(a),title(Main image);subplot(2,2,2),image(abs(F)),title(Haar spectrum);
65. 65. 65Slant Transform The Slant Transform matrix of order N*N is the recursive expression
66. 66. 66Slant Transform−=111121S2( )2122N1N4N3a −=Where I is the identity matrix, and( )2122N1N44Nb −−=
67. 67. 67Slant TransformExampleMain Image (Gray Level) Slant Transform of Main image(Slant spectrum)
68. 68. 68Slant TransformMATLAB program page 1 from 1.% Program written in Matlab for computing ST of a given gray color image.% Getting the name and extension of the image file from the user.name=input(Please write the name and address of the image : ,s);a=imread(name); N=length(a);% Computing Slant Transform of the image file.A=[ 1/(2^0.5) 1/(2^0.5);1/(2^0.5) -1/(2^0.5)];for i=2:log2(N) N=2^i; aN=((3*(N^2))/(4*((N^2)-1)))^0.5;bN=(((N^2)-4)/(4*((N^2)-1)))^0.5;m=1/(2^0.5)*[1 0 zeros(1,(N/2)-2) 1 0 zeros(1,(N/2)-2)aN bN zeros(1,(N/2)-2) -aN bN zeros(1,(N/2)-2)zeros((N/2)-2,2) eye((N/2)-2) zeros((N/2)-2,2) eye((N/2)-2)0 1 zeros(1,(N/2)-2) 0 -1 zeros(1,(N/2)-2)-bN aN zeros(1,(N/2)-2) bN aN zeros(1,(N/2)-2)zeros((N/2)-2,2) eye((N/2)-2) zeros((N/2)-2,2) -eye((N/2)-2)];n=[A A-A;A-A A]; A=m*n;endF=A*double(a)*A;% Changing the color map to gray scale (8 bits).colormap(gray(255));% Showing the main image and its Hadamard spectrum.subplot(2,2,1),image(a),title(Main image);subplot(2,2,2),image(abs(F)),title(Slant spectrum);
69. 69. 69Comparison Of Various Transforms
70. 70. 70Comparison Of Various Transforms
71. 71. 71Comparison Of Various Transforms
72. 72. 72Comparison Of Various Transforms
73. 73. 73References “Digital image processing” by Rafael C.Gonzalez and Richard E. Woods “Digital image processing” by Jain Image communication I by Bernd Girod Lecture 3, DCS339/AMCM053 by PengweiHao, University of London