Removing pattern and noise in an image using FFT in matlab

心已入冬 提交于 2019-12-02 20:34:25

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.

My code:

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),

i have recently written my notch filter for my homework,i struggled for finding an example code,here is my code i hope it will helps.thanks for all.

it is an ideal notch reject filter for removing periodic noises.

I = imread('clown.jpg'); %read image
I = imresize(I, [256 256]); %resize image
[m,n] = size(I);%get size of image as m and n
[X,Y]=meshgrid(1:256,1:256); % it is a meshgrid for circle mask
filter=ones(m,n); % filter initially only ones in it
%according to notch filter equation it will find point on image is on    imaginary circle.i found circle coordinates.
for i=1:m-1
  for j=1:n-1
  d0 = i-130)^2 + (j-130)^2 <= 32^2 && (i-130)^2 + (j-130)^2 >=20^2; 
      if d0
         filter(i,j)=0;
     else
         filter(i,j)=1;
     end
   end
 end
f = fftshift(fft2(I));
G = abs(ifft2(f.*filter));
figure(1),imshow(G,[]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!