Discrete Fourier Transform FFT and Its Applications FFTSHIFT

  • Slides: 20
Download presentation
Discrete Fourier Transform

Discrete Fourier Transform

FFT and Its Applications FFTSHIFT Shift zero-frequency component to the center of spectrum. For

FFT and Its Applications FFTSHIFT Shift zero-frequency component to the center of spectrum. For vectors, FFTSHIFT(X) swaps the left and right halves of X. For matrices, FFTSHIFT(X) swaps the first and third quadrants and the second and fourth quadrants. For N-D arrays, FFTSHIFT(X) swaps "half-spaces" of X along each dimension.

Example of 1 -D Fourier Transform

Example of 1 -D Fourier Transform

fft. Box. m – Plot Fourier Spectrum • • • • % % Script

fft. Box. m – Plot Fourier Spectrum • • • • % % Script file: fft. Box. m % Fourier Spectrum Plot of Box function % X 1=linspace(0, 1, 17); Y 1=ones(1, length(X 1)); X 2=linspace(1, 16, 241); Y 2=zeros(1, length(X 2)); X=[X 1 X 2]; Y=[Y 1 Y 2]; W=abs(fftshift(fft(Y))); subplot(2, 1, 1) plot(X, Y, 'r'); axis([0 16, 0, 1. 2]); title('Box function') subplot(2, 1, 2) plot(W, 'b-'); title('Fourier Spectrum of Box function')

2 -D Discrete Fourier Transform

2 -D Discrete Fourier Transform

Example of 2 -D FFT Matlab Code • • • • % Script file:

Example of 2 -D FFT Matlab Code • • • • % Script file: fourier. m - 2 D Fourier Transform % Pictures on P. 113 of Gonzalez, Woods, Eddins m=128; n=128; f=zeros(m, n); f(56: 71, 48: 79)=255; F 0=fft 2(f); S 0=abs(F 0); Fc=fftshift(fft 2(f)); Sc=abs(Fc); Fd=fft 2(fftshift(f)); Sd=log(1+abs(Fc)); subplot(2, 2, 1) imshow(f, []) subplot(2, 2, 2) imshow(S 0, []) subplot(2, 2, 3) imshow(Sc, [ ]) subplot(2, 2, 4) imshow(Sd, [ ])

2 -D FFT with Center. Shift

2 -D FFT with Center. Shift

2 -D FFT on Texture Images

2 -D FFT on Texture Images

Discrete Cosine Transform Partition an image into nonoverlapping 8 by 8 blocks, and apply

Discrete Cosine Transform Partition an image into nonoverlapping 8 by 8 blocks, and apply a 2 d DCT on each block to get DC and AC coefficients. Most of the high frequency coefficients become insignificant, only the DC term and some low frequency AC coefficients are significant. Fundamental for JPEG Image Compression

Discrete Cosine Transform (DCT) X: a block of 8 x 8 pixels A=Q 8:

Discrete Cosine Transform (DCT) X: a block of 8 x 8 pixels A=Q 8: 8 x 8 DCT matrix as shown above Y=AXAt

DCT on a 8 x 8 Block

DCT on a 8 x 8 Block

Quantized DCT Coefficients

Quantized DCT Coefficients

Matlab Code for 2 d DCT • • • • • Q=xlsread('Qtable. xls', 'A

Matlab Code for 2 d DCT • • • • • Q=xlsread('Qtable. xls', 'A 2: H 9'); fin=fopen('block 8 x 8. txt', 'r'); fout=fopen('dct. O. txt', 'w'); fgetl(fin); X=fscanf(fin, '%f', [8, 8]); fclose(fin); X=X'; Y=dct 2(X-128, [8, 8]); fprintf(fout, 'DCT coefficientsn'); for i=1: 8 for j=1: 8 fprintf(fout, '%6. 1 f', Y(i, j)); end; fprintf(fout, 'n'); end Y=Y. /Q; % Y=fix(Y+0. 5*(Y>0)); for i=1: 8 for j=1: 8 if (Y(i, j)>0) Y(i, j)=fix(Y(i, j)+0. 5); else Y(i, j)=fix(Y(i, j)-0. 5); end end fprintf(fout, 'Quantized DCT coefficientsn'); for i=1: 8 for j=1: 8 fprintf(fout, '%4 d', Y(i, j)); end; fprintf(fout, 'n'); end fclose(fout);

DCT-Based JPEG Conversion Input image write to file huffman encoding shift 128 DCT run-length

DCT-Based JPEG Conversion Input image write to file huffman encoding shift 128 DCT run-length encoding round convert 2 D matrix to 1 D array quantize with quantize matrix

Standard Quantization Table run-length encoding 產生一維結果: -26, -3, 0, ……, -1, 0, 0……. 後皆為零,簡化可以減少資料儲存量

Standard Quantization Table run-length encoding 產生一維結果: -26, -3, 0, ……, -1, 0, 0……. 後皆為零,簡化可以減少資料儲存量

JPEG Decoding image result shift 128 IDCT quantize with quantize matrix read compression file

JPEG Decoding image result shift 128 IDCT quantize with quantize matrix read compression file huffman decoding run-length decoding convert 1 D array to 2 D matrix

壓縮數據比較 原始檔案 Camera. Man Plusplus lena boats 原始大小 (壓縮比) 49. 3 KB 468 KB

壓縮數據比較 原始檔案 Camera. Man Plusplus lena boats 原始大小 (壓縮比) 49. 3 KB 468 KB 257 KB 188 KB 壓縮格式 壓縮大小 ----------------- zip --------- 42. 5 KB (82. 61%) 111 KB (23. 72%) 219 KB (85. 21%) 137 KB (72. 87%) rar --------- 36. 6 KB (74. 24%) 97. 3 KB (20. 79%) 164 KB (63. 81%) 116 KB (61. 7%) jpg --------- 12. 9 KB (26. 17%) 26. 5 KB (5. 662%) 62. 0 KB (24. 12%) 46. 6 KB (24. 79) project --------- 11. 2 KB (22. 75%) 9. 48 KB (2. 024%) 28. 1 KB (10. 95%) 24. 3 KB (12. 93%)