题目要求
图片
使用的是经典的Lena,其他图片集合已上传,免费下载。
Matlab代码
clear
close all
I = imread("Lena.tif");
noiseImage = imnoise(I,'gaussian',0,0.01);% 加入高斯噪声
subplot(231);imshow(I);title("原图像");
subplot(232);imshow(noiseImage);title("加噪声图像");
fI = fft2(double(I)); % 傅里叶变换
fnoiseImage = fft2(double(noiseImage));
S1 = abs(fftshift(fI)); % 取幅值
S2 = abs(fftshift(fnoiseImage));
subplot(2,3,4);imshow(log(1+S1),[]);title('原始图像频谱')
subplot(2,3,5);imshow(log(1+S2),[]);title('噪声图像频谱')
[M, N] = size(noiseImage);
P = 1*M;
Q = 1*N;
H = zeros(P, Q);
D0 = 50;
for u = 1:P % 理想低通滤波器
for v = 1:Q
D = sqrt((u-P/2)^2 + (v-Q/2)^2);
if D <= D0
H(u, v) = 1;
end
end
end
H_filter = fftshift(H);
G = fnoiseImage .* H_filter;
S3 = abs(fftshift(G));
subplot(236);imshow(log(1+S3),[]);title('滤波图像频谱');
g = ifft2(ifftshift(G)); % 反傅里叶变换
g = real(g);
subplot(233);imshow(g,[]);title('滤波图像')