各类滤波器的MATLAB程序清单.docx
- 文档编号:30512953
- 上传时间:2023-08-16
- 格式:DOCX
- 页数:17
- 大小:661.28KB
各类滤波器的MATLAB程序清单.docx
《各类滤波器的MATLAB程序清单.docx》由会员分享,可在线阅读,更多相关《各类滤波器的MATLAB程序清单.docx(17页珍藏版)》请在冰豆网上搜索。
各类滤波器的MATLAB程序清单
各类滤波器的MATLAB程序
一、理想低通滤波器
IA=imread('lena.bmp');
[f1,f2]=freqspace(size(IA),'meshgrid');
Hd=ones(size(IA));
r=sqrt(f1.^2+f2.^2);
Hd(r>0.2)=0;
Y=fft2(double(IA));
Y=fftshift(Y);
Ya=Y.*Hd;
Ya=ifftshift(Ya);
Ia=ifft2(Ya);
figure
subplot(2,2,1),imshow(uint8(IA));
subplot(2,2,2),imshow(uint8(Ia));
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
二、理想高通滤波器
IA=imread('lena.bmp');
[f1,f2]=freqspace(size(IA),'meshgrid');
Hd=ones(size(IA));
r=sqrt(f1.^2+f2.^2);
Hd(r<0.2)=0;
Y=fft2(double(IA));
Y=fftshift(Y);
Ya=Y.*Hd;
Ya=ifftshift(Ya);
Ia=real(ifft2(Ya));
figure
subplot(2,2,1),imshow(uint8(IA));
subplot(2,2,2),imshow(uint8(Ia));
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
三、Butterworth低通滤波器
IA=imread('lena.bmp');
[f1,f2]=freqspace(size(IA),'meshgrid');
D=0.3;
r=f1.^2+f2.^2;
n=4;
fori=1:
size(IA,1)
forj=1:
size(IA,2)
t=r(i,j)/(D*D);
Hd(i,j)=1/(t^n+1);
end
end
Y=fft2(double(IA));
Y=fftshift(Y);
Ya=Y.*Hd;
Ya=ifftshift(Ya);
Ia=real(ifft2(Ya));
figure
subplot(2,2,1),imshow(uint8(IA));
subplot(2,2,2),imshow(uint8(Ia));
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
四、Butterworth高通滤波器
IA=imread('lena.bmp');
[f1,f2]=freqspace(size(IA),'meshgrid');
D=0.3;
r=f1.^2+f2.^2;
n=4;
fori=1:
size(IA,1)
forj=1:
size(IA,2)
t=(D*D)/r(i,j);
Hd(i,j)=1/(t^n+1);
end
end
Y=fft2(double(IA));
Y=fftshift(Y);
Ya=Y.*Hd;
Ya=ifftshift(Ya);
Ia=real(ifft2(Ya));
figure
subplot(2,2,1),imshow(uint8(IA));
subplot(2,2,2),imshow(uint8(Ia));
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
五、高斯低通滤波器
IA=imread('lena.bmp');IB=imread('babarra.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);
end
end
Y=fft2(double(IA));
Y=fftshift(Y);
Ya=Y.*Hd;
Ya=ifftshift(Ya);
Ia=real(ifft2(Ya));
figure
subplot(2,2,1),imshow(uint8(IA));
subplot(2,2,2),imshow(uint8(Ia));
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
六、高斯高通滤波器
IA=imread('lena.bmp');IB=imread('babarra.bmp');
[f1,f2]=freqspace(size(IA),'meshgrid');
%D=100/size(IA,1);
D=0.3;
r=f1.^2+f2.^2;
fori=1:
size(IA,1)
forj=1:
size(IA,2)
t=r(i,j)/(D*D);
Hd(i,j)=1-exp(-t);
end
end
Y=fft2(double(IA));
Y=fftshift(Y);
Ya=Y.*Hd;
Ya=ifftshift(Ya);
Ia=real(ifft2(Ya));
figure
subplot(2,2,1),imshow(uint8(IA));
subplot(2,2,2),imshow(uint8(Ia));
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
七、梯形低通滤波器
IA=imread('lena.bmp');IB=imread('babarra.bmp');
[f1,f2]=freqspace(size(IA),'meshgrid');
%D=100/size(IA,1);
D0=0.1;
D1=0.4;
r=sqrt(f1.^2+f2.^2);
Hd=zeros(size(IA));
Hd(r fori=1: size(IA,1) forj=1: size(IA,2) ifr(i,j)>=D0&r(i,j)<=D1 Hd(i,j)=(D1-r(i,j))/(D1-D0); end end end Y=fft2(double(IA)); Y=fftshift(Y); Ya=Y.*Hd; Ya=ifftshift(Ya); Ia=real(ifft2(Ya)); figure subplot(2,2,1),imshow(uint8(IA)); subplot(2,2,2),imshow(uint8(Ia)); figure surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong'); 八、梯形高通滤波器 IA=imread('lena.bmp');IB=imread('babarra.bmp'); [f1,f2]=freqspace(size(IA),'meshgrid'); %D=100/size(IA,1); D0=0.1; D1=0.4; r=sqrt(f1.^2+f2.^2); Hd=ones(size(IA)); Hd(r fori=1: size(IA,1) forj=1: size(IA,2) ifr(i,j)>=D0&r(i,j)<=D1 Hd(i,j)=(D0-r(i,j))/(D0-D1); end end end Y=fft2(double(IA)); Y=fftshift(Y); Ya=Y.*Hd; Ya=ifftshift(Ya); Ia=real(ifft2(Ya)); figure subplot(2,2,1),imshow(uint8(IA)); subplot(2,2,2),imshow(uint8(Ia)); figure surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong'); 九、用其他方法编写的理想低通、理想高通、Butterworth低通、同态滤波程序 1、理想低通 i1=imread('lena.bmp'); i2=imnoise(i1,'salt&pepper',0.1); f=double(i2); k=fft2(f); g=fftshift(k); [N1,N2]=size(g); d0=50; u0=floor(N1/2)+1; v0=floor(N2/2)+1; fori=1: N1 forj=1: N2 d=sqrt((i-u0)^2+(j-v0)^2); ifd<=d0 h=1; else h=0; end y(i,j)=g(i,j)*h; end end y=ifftshift(y); E1=ifft2(y); E2=real(E1); figure subplot(2,2,1),imshow(uint8(i1)); subplot(2,2,2),imshow(uint8(i2)); subplot(2,2,3),imshow(uint8(E2)); 2、理想高通 i1=imread('lena.bmp'); i2=imnoise(i1,'salt&pepper',0.1); f=double(i2); k=fft2(f); g=fftshift(k); [N1,N2]=size(g); n=2; d0=10; u0=floor(N1/2)+1; v0=floor(N2/2)+1; fori=1: N1 forj=1: N2 d=sqrt((i-u0)^2+(j-v0)^2); ifd<=d0 h=0; elseh=1; end y(i,j)=g(i,j)*h; end end y=ifftshift(y); E1=ifft2(y); E2=real(E1); figure subplot(2,2,1),imshow(uint8(i1)); subplot(2,2,2),imshow(uint8(i2)); subplot(2,2,3),imshow(uint8(E2)); 3、Butterworth低通 i1=imread('lena.bmp'); i2=imnoise(i1,'salt&pepper',0.1); f=double(i2); k=fft2(f); g=fftshift(k); [N1,N2]=size(g); n=2; d0=50; u0=floor(N1/2)+1; v0=floor(N2/2)+1; fori=1: N1 forj=1: N2 d=sqrt((i-u0)^2+(j-v0)^2); h=1/(1+(d/d0)^(2*n)); y(i,j)=g(i,j)*h; end end y=ifftshift(y); E1=ifft2(y); E2=real(E1); figure subplot(2,2,1),imshow(uint8(i1)); subplot(2,2,2),imshow(uint8(i2)); subplot(2,2,3),imshow(uint8(E2)); 4、同态滤波 I=rgb2gray(imread('fabric00.bmp')); [M,N]=size(I); T=double(I); L=log(T); F=fft2(L); A=2; B=0.3; fori=1: M forj=1: N D(i,j)=((i-M/2)^2+(j-N/2)^2); end end c=1.1;%锐化参数 D0=max(M,N); H=(A-B)*(1-exp(c*(-D/(D0^2))))+B; F=F.*H; F=ifft2(F); Y=exp(F); figure subplot(1,2,1),imshow(I); subplot(1,2,2),imshow(uint8(real(Y))); 十、Gabor滤波器
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 各类 滤波器 MATLAB 程序 清单
![提示](https://static.bdocx.com/images/bang_tan.gif)