【matlab】图像去噪的代码测试

%% 自己设置频域的滤波窗口
girl=imread('F:\Users\*****\Pictures\CGS_stripe1.bmp');
girl=rgb2gray(girl);
girl=im2double(girl);
subplot(1,2,1);imshow(girl);%显示原始图像
title('原始图像'); 
G=fft2(double(girl));% 二维傅里叶变换
G=fftshift(G);%象限转换
subplot(1,2,2);imshow(log(abs(G)+1),[ ]);%显示原始图像频谱图
title('原始图像频谱图');figure;
%构造理想低通滤波器,并用它滤波
[height  width]=size(G);
H(1: height,1: width)=0.9;
x0= height/2; y0= width/2;%确定原点
for x=1:height
    for y=1:width
        if(sqrt((x- x0)*(x- x0)+(y-y0)*(y-y0))>15) %确定滤波半径
            H(x,y)=1;
        end
        F(x,y)=G(x,y)*H(x,y);
    end
end
imshow(log(abs(F)+1),[ ]);%显示中间图像频谱图
title('中间图像频谱图');
g=ifft2(F);% 傅里叶反变换
figure;imshow(abs(real(g)),[ ]);%显示处理后的图像
title('处理后的图像');

猜你喜欢

转载自www.cnblogs.com/wxl845235800/p/10222296.html