I=imread('D:\0.png');
I=rgb2gray(I);
I1=imnoise(I,'gaussian',0.1,0.005);
subplot(2,2,1),imshow(I),title('原始图');
subplot(2,2,2),imshow(I1),title('加高斯噪声');
m=double(I1);
f=fft2(m);
f=fftshift(f);
[N1,N2]=size(f);
n1=round(N1/2);
n2=round(N2/2);
n=2;d0=10;
for i=1:N1
for j=1:N2
d=sqrt((i-n1)^2+(j-n2)^2);
h=(1/(1+(d0/d)^(2*n)))+0.5;
y(i,j)=h*f(i,j);
end
end
y=ifftshift(y);
A=ifft2(y);
B=uint8(real(A));
subplot(2,2,3),imshow(B),title('巴特沃斯高通滤波器');
g=fft2(double(I));
g=fftshift(g);
[N1,N2]=size(g);
n=2;
d0=30;
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
for j=1:N2
d=sqrt((i-n1)^2+(j-n2)^2);
h=1-exp(-d*d/(2*d0*d0));
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
X2=ifft2(result);
final=uint8(real(X2));
subplot(2,2,4),imshow(final),title('高斯高通滤波器');