基于matlab数字图像处理之低通滤波器

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实践一:理想低通滤波器、Butterworth低通滤波器、高斯低通滤波器1.1.1理想低通滤波器实践代码: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('图像傅里叶变换取对数所得频谱');[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');Hd=ones(size(I));Hd(r0.2)=0;figuresurf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');%画三维曲面(色)图1.1.2理想低通滤波器实践结果截图:1.2.1Butterworth低通滤波器实践代码:clearall;I1=imread('girl.bmp');subplot(221),imshow(I1);xlabel('(a)原始图像');f=double(I1);%数据类型转换g=fft2(f);%图像傅里叶转换g=fftshift(g);%傅里叶变换平移F2=log(abs(g));%对傅里叶变换结果取绝对值,然后取对数subplot(222),imshow(F2,[],'InitialMagnification','fit');%将计算后的矩阵用图像表示colormap(jet);%设置色彩索引图colorbar%显示色彩索引条xlabel('(b)原始图像的傅里叶变换图像');[N1,N2]=size(g);%傅里叶变换图像尺寸n=2;%参数赋初始值d0=5;n1=fix(N1/2);%数据圆整n2=fix(N2/2);%数据圆整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);%图像矩阵计算处理endendF3=log(abs(result));%对傅里叶变换结果取绝对值,然后取对数subplot(223),imshow(F3,'InitialMagnification','fit');colormap(jet);%设置色彩索引图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+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低通滤波器实践结果截图:1.3.1高斯低通滤波器实践代码:IA=imread('girl.bmp');[f1,f2]=freqspace(size(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(2,2,1),imshow(uint8(IA));title('原图像');subplot(2,2,2),imshow(uint8(Ia));title('高斯低通滤波处理');figuresurf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');%画三维曲面(色)图1.3.2高斯低通滤波器实践结果截图:

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功