Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Fourier Transform. FFT and Its Applications FFTSHIFT Shift zero-frequency component to the center of spectrum. For vectors, FFTSHIFT(X) swaps.

Similar presentations


Presentation on theme: "Discrete Fourier Transform. FFT and Its Applications FFTSHIFT Shift zero-frequency component to the center of spectrum. For vectors, FFTSHIFT(X) swaps."— Presentation transcript:

1 Discrete Fourier Transform

2 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.

3 Example of 1-D Fourier Transform

4 fftBox.m – Plot Fourier Spectrum % % Script file: fftBox.m % Fourier Spectrum Plot of Box function % X1=linspace(0,1,17); Y1=ones(1,length(X1)); X2=linspace(1,16,241); Y2=zeros(1,length(X2)); X=[X1 X2]; Y=[Y1 Y2]; 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')

5 2-D Discrete Fourier Transform

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

7 2-D FFT with CenterShift

8 2-D FFT on Texture Images

9 Discrete Cosine Transform Partition an image into nonoverlapping 8 by 8 blocks, and apply a 2d 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

10 Discrete Cosine Transform (DCT) X: a block of 8x8 pixels A=Q 8 : 8x8 DCT matrix as shown above Y=AXA t

11 DCT on a 8x8 Block

12 Quantized DCT Coefficients

13 Matlab Code for 2d DCT Q=xlsread('Qtable.xls','A2:H9'); fin=fopen('block8x8.txt','r'); fout=fopen('dctO.txt','w'); fgetl(fin); X=fscanf(fin,'%f',[8,8]); fclose(fin); X=X'; Y=dct2(X-128,[8,8]); fprintf(fout,'DCT coefficients\n'); for i=1:8 for j=1:8 fprintf(fout,'%6.1f',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 coefficients\n'); for i=1:8 for j=1:8 fprintf(fout,'%4d',Y(i,j)); end; fprintf(fout,'\n'); end fclose(fout);

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

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

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

17 未採用流程

18 壓縮結果差異

19 壓縮數據比較 原始檔案 CameraManPluspluslenaboats 原始大小 ( 壓縮比 ) 49.3 KB468 KB257 KB188 KB 壓縮格式壓縮大小 ----------------- zip ----------------- 42.5KB (82.61%) 111KB (23.72%) 219KB (85.21%) 137KB (72.87%) rar ----------------- 36.6KB (74.24%) 97.3KB (20.79%) 164KB (63.81%) 116KB (61.7%) jpg ----------------- 12.9KB (26.17%) 26.5KB (5.662%) 62.0KB (24.12%) 46.6KB (24.79) project ----------------- 11.2KB (22.75%) 9.48KB (2.024%) 28.1KB (10.95%) 24.3KB (12.93%)

20 壓縮數據比較


Download ppt "Discrete Fourier Transform. FFT and Its Applications FFTSHIFT Shift zero-frequency component to the center of spectrum. For vectors, FFTSHIFT(X) swaps."

Similar presentations


Ads by Google