資源描述:
《基于matlab數(shù)字圖像處理之低通濾波器》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、實(shí)踐一:理想低通濾波器、Butterworth低通濾波器、高斯低通濾波器1.1.1理想低通濾波器實(shí)踐代碼:I=imread('couple.bmp');%I=rgb2gray(I);subplot(221),imshow(I);title('原圖像');s=fftshift(fft2(I));subplot(223),imshow(abs(s),[]);title('圖像傅里葉變換所得頻譜');subplot(224),imshow(log(abs(s)),[]);title('圖像傅里葉變換取對(duì)數(shù)所
2、得頻譜');[a,b]=size(s);a0=round(a/2);b0=round(b/2);d=10;fori=1:aforj=1:bdistance=sqrt((i-a0)^2+(j-b0)^2);ifdistance<=dh=1;elseh=0;end;s(i,j)=h*s(i,j);end;end;s=uint8(real(ifft2(ifftshift(s))));subplot(222),imshow(s);title('低通濾波所得圖像');I=imread('couple.bmp')
3、;Hd=ones(size(I));Hd(r>0.2)=0;figuresurf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');%畫三維曲面(色)圖1.1.2理想低通濾波器實(shí)踐結(jié)果截圖:1.2.1Butterworth低通濾波器實(shí)踐代碼:clearall;I1=imread('girl.bmp');subplot(221),imshow(I1);xlabel('(a)原始圖像');f=double(I1);%數(shù)據(jù)類
4、型轉(zhuǎn)換g=fft2(f);%圖像傅里葉轉(zhuǎn)換g=fftshift(g);%傅里葉變換平移F2=log(abs(g));%對(duì)傅里葉變換結(jié)果取絕對(duì)值,然后取對(duì)數(shù)subplot(222),imshow(F2,[],'InitialMagnification','fit');%將計(jì)算后的矩陣用圖像表示colormap(jet);%設(shè)置色彩索引圖colorbar%顯示色彩索引條xlabel('(b)原始圖像的傅里葉變換圖像');[N1,N2]=size(g);%傅里葉變換圖像尺寸n=2;%參數(shù)賦初始值d0=5;n
5、1=fix(N1/2);%數(shù)據(jù)圓整n2=fix(N2/2);%數(shù)據(jù)圓整fori=1:N1%遍歷圖像像素forj=1:N2d=sqrt((i-n1)^2+(j-n2)^2);ifd==0h=0;elseh=1/(1+(d/d0)^(2*n));endresult(i,j)=h*g(i,j);%圖像矩陣計(jì)算處理endendF3=log(abs(result));%對(duì)傅里葉變換結(jié)果取絕對(duì)值,然后取對(duì)數(shù)subplot(223),imshow(F3,'InitialMagnification','fit');c
6、olormap(jet);%設(shè)置色彩索引圖colorbar%顯示色彩索引條xlabel('(c)濾波后的傅里葉變換圖像')result=ifftshift(result);X2=ifft2(result);X3=uint8(real(X2));subplot(224),imshow(X3)xlabel('(d)Butterworth低通濾波圖像');I1=imread('couple.bmp');[f1,f2]=freqspace(size(I1),'meshgrid');D=0.3;r=f1.^2+
7、f2.^2;n=4;fori=1:size(I1,1)forj=1:size(I1,2)t=r(i,j)/(D*D);Hd(i,j)=1/(t^n+1);endendsurf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');%畫三維曲面(色)圖1.2.2Butterworth低通濾波器實(shí)踐結(jié)果截圖:1.3.1高斯低通濾波器實(shí)踐代碼:IA=imread('girl.bmp');[f1,f2]=freqspace(siz
8、e(IA),'meshgrid');D=100/size(IA,1);r=f1.^2+f2.^2;Hd=ones(size(IA));fori=1:size(IA,1)forj=1:size(IA,2)t=r(i,j)/(D*D);Hd(i,j)=exp(-t);endendY=fft2(double(IA));Y=fftshift(Y);Ya=Y.*Hd;Ya=ifftshift(Ya);Ia=real(ifft2(Ya));figuresubplot