MATLAB将一幅含有噪声的图像频谱通过低通滤波器,观察滤波前后图像发生的变化。

主要代码如下

clc;
An=imread('noise.bmp');
A=rgb2gray(An);
subplot(1,3,1);
imshow(An);title('噪声图像');
F=fftshift(fft2(A));
subplot(1,3,2);
imshow(log(abs(F)),[10,12]);title('傅里叶变化');
d0=50;
[M,N]=size(A);
n1=floor(M/2);
n2=floor(N/2);
for m=1:M
    for n=1:N
        d=sqrt((m-n1)*(m-n1)+(n-n2)*(n-n2));
        if d<=d0
            h=1;
        else
            h=0;  
        end
        B(m,n)=h*F(m,n);
    end
end
Bi=ifft2(ifftshift(B));
subplot(1,3,3);
imshow(uint8(real(Bi)));title('滤波后');

运行截图:

 

おすすめ

転載: blog.csdn.net/y0205yang/article/details/121315217