# Matlab练习：图像去噪（二维图像的FFT&FFT滤波器的综合应用）

``````%去除斜线噪声
clear,clc,close all;
I=im2double(i);
I1=mean(I,3);
figure,imshow(I1),title('1) Original Image');
x=zeros(850,850);
x(3:847,64:786)=I1;
figure,imshow(x),title('1) Square Image');
If=fft2(x);
figure,imshow(If),title('If');
If1=fftshift(If);
figure,imshow(If1),title('If1');
If2=abs(If1);
figure,imshow(If2),title('If2');
If3=log(If2);
[m,~]=size(If3);
freq=-m/2:m/2-1;
figure,imagesc(freq,freq,If3),title('1) FFT Image');
b=zeros(850,850);
for i=1:m
for j=1:m
if(i-460)^2+(j-390)^2>=17^2&&(i-390)^2+(j-460)^2>=17^2
b(i,j)=1;
end
end
end
figure,imagesc(b),title('1) Filter');
I2=If1.*b;
figure,imshow(I2),title('I2');
I3=ifft2(I2);
figure,imshow(I3),title('I3');
I4=abs(I3);
figure,imshow(I4),title('1) Final Square Image');
I5=I4(3:847,64:786);
figure,imshow(I5),title('1) Final Image');
imwrite(I4,'1) Final Square Image.jpg');
imwrite(I5,'1) Final Image.jpg');``````

``````%去除横线噪声
clear,clc,close all;
I1=im2double(i);
figure,imshow(I1),title('2) Original Image');
If=fft2(I1);
figure,imshow(If),title('If');
If1=fftshift(If);
figure,imshow(If1),title('If1');
If2=abs(If1);
figure,imshow(If2),title('If2');
If3=log(If2);
[m,~]=size(If3);
freq=-m/2:m/2-1;
figure,imagesc(freq,freq,If3),title('2) FFT Image');
b=ones(850,850);
b(1:420,420:430)=0;
b(430:850,420:430)=0;
figure,imagesc(b),title('2) Filter Image');
I2=If1.*b;
figure,imshow(I2),title('I2');
I3=ifft2(I2);
figure,imshow(I3),title('I3');
I4=abs(I3);
figure,imshow(I4),title('2) Final Square Image');
I5=I4(3:847,64:786);
figure,imshow(I5),title('2) Final Image');
imwrite(I5,'2) Final Image.jpg');``````

THE END

)">