且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在matlab中使用FFT去除图像中的图案和噪声

更新时间:2023-02-27 10:50:29

我试图检测到频域,并将其与邻域一起归零。它不完全是干净的,但至少在一定程度上实现了一些自动调零。

I tried to detect the local maximum magnitude in the frequency domain, and zero them along with their neighborhoods. It is not exactly clean, but at least realize some automatic-zero to some extent.

我的代码:

I=I-mean(I(:));
f = fftshift(fft2(I));
fabs=abs(f);

roi=3;thresh=400;
local_extr = ordfilt2(fabs, roi^2, ones(roi));  % find local maximum within 3*3 range

result = (fabs == local_extr) & (fabs > thresh);

[r, c] = find(result);
for i=1:length(r)
    if (r(i)-128)^2+(c(i)-128)^2>400   % periodic noise locates in the position outside the 20-pixel-radius circle
        f(r(i)-2:r(i)+2,c(i)-2:c(i)+2)=0;  % zero the frequency components
    end
end

Inew=ifft2(fftshift(f));
imagesc(real(Inew)),colormap(gray),