1、低通滤波
1.1对图像eight.tif加入椒盐噪声后,实现Butterworth低通滤波。
clear;
I1=imread('eight.tif');
subplot(221),imshow(I1),title('原始图像');
I2=imnoise(I1,'salt & pepper'); %加入椒盐噪声
subplot(222),imshow(I2),title('噪声图像');
f=double(I2);
g=fft2(f); %傅里叶变换
g=fftshift(g) %转换数据矩阵
[N1,N2]=size(g);
n=2;
d0=50;
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
for j=2:N2
d=sqrt((i-n1)^2+(j-n2)^2); %计算Butterworth低通滤波转换函数
h=1/(1+0.414*(d/d0)^(2*n));
result1(i,j)=h*g(i,j);
if(g(i,j)>50) %进行理想低通滤波
result2(i,j)=0;
else
result2(i,j)=g(i,j);
end
end
end
result1=ifftshift(result1); %进行反变换
result2=ifftshift(result2); %进行反变换
X2=ifft2(result1);
X3=uint8(real(X2));
subplot(223),imshow(X3),title('Butterworth滤波图像');
X4=iff