【正文】
),title(39。Gaussian high filter39。)。 高斯高通濾波器 (2)讀出一幅圖像,分別采用理想高通濾波器、巴特沃斯高通濾波器和高斯高通濾波器對 其進(jìn)行濾波(截至頻率自選),再做反變換,觀察不同的截止頻率下采用不同高通濾波器得 到的圖像與原圖像的區(qū)別。 %理想高通濾波 img=imread(39。39。)。 img=rgb2gray(img)。 f=double(img)。 g=fft2(f)。 %傅立葉變換 g=fftshift(g)。 [M,N]=size(g)。 d0=15。 m=fix(M/2)。 n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 if(d=d0) h=1。 else h=0。 end result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 figure,subplot(2,2,1),imshow(img),title(39。Original Image39。)。 subplot(2,2,2),imshow(J2),title(39。d0=15 high filter39。)。 d0=30。 m=fix(M/2)。 n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 if(d=d0) h=1。 else h=0。 end result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 subplot(2,2,3),imshow(J2),title(39。d0=30 high filter39。)。 d0=80。 m=fix(M/2)。 n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 if(d=d0) h=1。 else h=0。 end result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 subplot(2,2,4),imshow(J2),title(39。d0=80 high filter39。)。 理想高通濾波器得到的圖片效果為: 當(dāng) d0=15 時,濾波后的圖像灰度變化部分基本保留; 當(dāng) d0=30 時,圖像的輪廓還比較清楚; %巴特沃斯高通濾波 img=imread(39。39。)。 img=rgb2gray(img)。 f=double(img)。 g=fft2(f)。 %傅立葉變換 g=fftshift(g)。 [M,N]=size(g)。 nn=2。 d0=15。 m=fix(M/2),n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 if(d==0) h=0。 else h=1/(1+*(d0/d)^(2*nn))。 end result(i,j)=h*g(i,j)。 end 當(dāng) d0=80 時,只能看到細(xì)微的圖像輪廓; end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 figure,subplot(2,2,1),imshow(img),title(39。Original Image39。)。 subplot(2,2,2),imshow(J2),title(39。d0=15 Butterworth high filter39。)。 d0=30。 m=fix(M/2),n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 if(d==0) h=0。 else h=1/(1+*(d0/d)^(2*nn))。 end result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 subplot(2,2,3),imshow(J2),title(39。d0=30 Butterworth high filter39。)。 d0=80。 m=fix(M/2),n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 if(d==0) h=0。 else h=1/(1+*(d0/d)^(2*nn))。 end result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 subplot(2,2,4),imshow(J2),title(39。d0=80 Butterworth high filter39。)。 n=2 時的巴特沃斯高通濾波效果為: %高斯高通濾波器 img=imread(39。39。)。 img=rgb2gray(img)。 f=double(img)。 g=fft2(f)。 %傅立葉變換 g=fftshift(g)。 [M,N]=size(g)。 n=2。 d0=15。 m=fix(M/2),n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 h=1exp((d.^2)./(2*(d0^2)))。 result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 figure,subplot(2,2,1),imshow(img),title(39。Original Image39。)。 subplot(2,2,2),imshow(J2),title(39。d0=15 Gaussian filter39。)。 d0=30。 m=fix(M/2),n=fix(N/2)。 濾波結(jié)果比理想高通濾波器更加平滑,邊緣失真情況較小。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 h=1exp((d.^2)./(2*(d0^2)))。 result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 subplot(2,2,3),imshow(J2),title(39。d0=30 Gaussian filter39。)。 d0=80。 m=fix(M/2),n=fix(N/2)。 for i=1:M for j=1:N d=sqrt((im)^2+(jn)^2)。 h=1exp((d.^2)./(2*(d0^2)))。 result(i,j)=h*g(i,j)。 end end result=ifftshift(result)。 J1=ifft2(result)。 J2=uint8(real(J1))。 subplot(2,2,4),imshow(J2),title(39。d0=80 Gaussian filter39。)。 高斯高通濾波效果為: 高斯高通的濾波效果在這 3 種濾波器中最為平滑,過濾效果比較清晰。