天天看點

數字圖像的變換傅裡葉變換

傅裡葉變換

傅裡葉變換是最簡單的正交變換,它是了解其他變換的基礎,同時也是應用最廣泛的一種正交變換。傅裡葉變換建立了從時間域到頻率域的橋梁。   

傅裡葉變換的實作

%實作圖像的傅裡葉變換
I=imread('cameraman.tif');
subplot(131);imshow(I);
title('原始圖像');
J=fft2(I);%傅裡葉變換
subplot(132);imshow(J);
title('傅裡葉變換後的圖像');
K=ifft2(J)/255;%傅裡葉逆變換
subplot(133);imshow(K);
title('傅裡葉逆變換後圖像');
           

結果:

數字圖像的變換傅裡葉變換
%圖像變亮後進行傅裡葉變換
I=imread('peppers.png');
J=rgb2gray(I);
J=J*exp(1);
J(find(J>255))=255;
K=fft2(J);
K=fftshift(K);
L=abs(K/256);
figure;
subplot(121);imshow(J);
title('變亮後的圖像');
subplot(122);imshow(uint8(L));%頻譜圖
title('頻譜圖');
           

結果:

數字圖像的變換傅裡葉變換
%在圖像text.tif中定位字母“a”
bw=imread('text.png');
a=bw(32:45,88:98);
subplot(1,2,1);imshow(bw);
title('原始圖像');
subplot(1,2,2);imshow(a);
title('模闆圖像');
           

結果:

數字圖像的變換傅裡葉變換
%将模闆“a”和“text.png”圖進行相關運算,就是先分别對其作快速傅裡葉變換,然後利用快速卷積的方法,計算模闆和text.png的卷積。
bw=imread('text.png');
a=bw(32:45,88:98);%從圖像中提取字母“a”。
C=real(ifft2(fft2(bw).*fft2(rot90(a,2),256,256)));
subplot(121),imshow(C,[]);
title('模闆與卷積')
max(C(:))
thresh=60  %設定門限
subplot(122),imshow(C>thresh)
title('a字母定位')
           

 結果:

數字圖像的變換傅裡葉變換

濾波器的應用

%對圖像進行巴特沃斯低通濾波器
I=imread('cameraman.tif');
I=im2double(I);
J=fftshift(fft2(I));%傅裡葉變換和平移
[x,y]=meshgrid(-128:127,-128:127);%産生離散資料
z=sqrt(x.^2+y.^2);
D1=10;D2=35;
n=6;%濾波器的階數
H1=1./(1+(z/D1).^(2*n));%濾波器
H2=1./(1+(z/D2).^(2*n));
K1=J.*H1;
K2=J.*H2;
L1=ifft2(ifftshift(K1));%傅裡葉反變換
L2=ifft2(ifftshift(K2));
subplot(131);imshow(I);
title('原始圖像');
subplot(132);imshow(L1);%顯示載頻頻率為10hz
title('巴特沃斯低通濾波器');
subplot(133);imshow(L2);%顯示載頻頻率為35hz
title('巴特沃斯低通濾波器');
           

結果:

數字圖像的變換傅裡葉變換
%對圖像進行巴特沃斯高通濾波器
I=imread('cameraman.tif');
I=im2double(I);
J=fftshift(fft2(I));%傅裡葉變換和平移
[x,y]=meshgrid(-128:127,-128:127);%産生離散資料
z=sqrt(x.^2+y.^2);
D1=10;D2=35;
n1=4;n2=8;%濾波器的階數
H1=1./(1+(z/D1).^(2*n1));%濾波器
H2=1./(1+(z/D2).^(2*n2));
K1=J.*H1;
K2=J.*H2;
L1=ifft2(ifftshift(K1));%傅裡葉反變換
L2=ifft2(ifftshift(K2));
subplot(131);imshow(I);
title('原始圖像');
subplot(132);imshow(L1);%顯示載頻頻率為10hz
title('巴特沃斯低通濾波器');
subplot(133);imshow(L2);%顯示載頻頻率為35hz
title('巴特沃斯低通濾波器');
           

結果:

數字圖像的變換傅裡葉變換
下一篇: Path

繼續閱讀