同学那里copy来的代码,仅供使用时参考
理想低通滤波器
M=256;
N=256;
d0=50;
m=fix(M/2);
n=fix(N/2);
%h=zeros(256,256);
for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
if(d<=d0)
h(i,j)=1;
else
h(i,j)=0;
end
end
end
mesh(h)
巴特沃斯低通滤波器
clc;
clear;
M=256;
N=256;
d0=50;
n=2;
m=fix(M/2);
n=fix(N/2);
%h=zeros(256,256);
for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
h(i,j)=1/(1+0.414*(d/d0)^(2*2));
end
end
mesh(h)
axis off
高斯低通滤波器
clc;clear;
M=256;
N=256;
d0=50;
m=fix(M/2);
n=fix(N/2);
%h=zeros(256,256);
for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
h(i,j)=exp(-(d^2)/(2*(d0^2)));
end
end
mesh(h)
axis off