实践二:理想高通滤波器、Butterworth高通滤波器、高斯高通滤波器
2.1.1理想高通滤波器实践代码:
I=imread('');
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;
p=;q=;
fori=1:a
forj=1:b
distance=sqrt((i-a0)^2+(j-b0)^2);
ifdistance<=dh=0;
elseh=1;
end;
s(i,j)=(p+q*h)*s(i,j);
end;
end;
s=uint8(real(ifft2(ifftshift(s))));
subplot(222),
imshow(s);title('高通滤波所得图像');
I=imread('');
[f1,f2]=freqspace(size(I),'meshgrid');
Hd=ones(size(I));
r=sqrt(f1.^2+f2.^2);
Hd(r<=0;
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');%画三维曲面(色)图
2.1.2理想高通滤波器实践结果截图:
2.2.1Butterworth高通滤波器实践代码:
I1=imread('');
subplot(121),imshow(I1);
title('原始图像');
f=double(I1);
g=fft2(f);
g=fftshift(g);
[N1,N2]=size(g);
n=2;
d0=5;
n1=fix(N1/2);
n2=fix(N2/2);
fori=1:N1
forj=1:N2
d=sqrt((i-n1)^2+(j-n2)^2);
ifd==0
h=0;
else
h=1/(1+(d0/d)^(2*n));
end
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
X2=ifft2(result);
X3=uint8(real(X2));
subplot(122),imshow(X3);
title('Butterworth高通滤波');
I1=imread('');
[f1,f2]=freqspace(size(I1),'meshgrid');
D=;
r=f1.^2+f2.^2;
n=4;
fori=1:size(I1,1)
forj=1:size(I1,2)
t=(D*D)/r(i,j);
Hd(i,j)=1/(t^n+1);
end
end
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');%画三维曲面(色)图
2.2.2Butterworth高通滤波器实践结果截图:
2.3.1高斯高通滤波器实践代码:
clearall
IA=imread('');
[f1,f2]=freqspace(size(IA),'meshgrid');
%D=100/size(IA,1);
D=;
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));title('原始图像');
subplot(2,2,2),imshow(uint8(Ia));title('高斯高通滤波');
figure
surf(Hd,'Facecolor','interp','Edgecolor','none','Facelighting','phong');
2.3.2高斯高通滤波器实践结果截图:。