Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find proper notch filter to remove pattern from image

I want to apply notch filter on an image where it suppresses the pattern in the image but leave the rest of the image as intact as possible. i do the following steps :

I = imread('...img....');
ft = fftshift(fft2(I));
[m,n] = size(ft);
filt = ones(m,n);
%filt(......) = 0; % my problem is here 
ft = ft .* filt;
ifft_ = ifft2(ifftshift( ft));

so i don't know what exactly to set to zero to get the proper result. enter image description here

like image 448
Yazan Houshieh Avatar asked Mar 24 '15 14:03

Yazan Houshieh


People also ask

What is notch filter in image processing?

A notch filter (NF) is a band-rejection filter that significantly attenuates specific frequency signals but passes all other frequency components with negligible attenuation.

How do you remove periodic noise from a picture?

The periodic noise can not be removed from digital images in the spatial domain. This is the only way to remove periodic noise by converting the image into the frequency domain. The only condition is that we need to spot the noise pattern in the Fourier transform the image to get the quality image.

How do you make a notch filter?

One way to build a notch filter is to construct it as a band-pass filter whose output is subtracted from the input (1 – BP). Another way is with cascaded low-pass and high-pass sections, especially for the band-reject (wideband) case. In this case, the sections are in parallel, and the output is the difference.


Video Answer


2 Answers

If you take a look at the fft of the image you can clearly see the strong frequencies that are causing the pattern in the image.

enter image description here

You need to create a notch filter which zeros out the region around those high peaks. I tried using Gaussian notch filters for this operation and the resulting spectrum looked something like this.

enter image description here

The ifft image (with contrast enhanced) turns out to be

enter image description here

Here's some MATLAB code used to build and apply the filter

I = imread('YmW3f.png');
ft = fftshift(fft2(I));
[m,n] = size(ft);

% define some functions
norm_img = @(img) (img - min(img(:))) / (max(img(:)) - min(img(:)));
show_spec = @(img) imshow(norm_img(log(abs(img)-min(abs(img(:)))+1.0001)));
gNotch = @(v,mu,cov) 1-exp(-0.5*sum((bsxfun(@minus,v,mu).*(cov\bsxfun(@minus,v,mu)))));

% show spectrum before
figure();
show_spec(ft);

% by inspection
cx = 129;
cy = 129;

% distance of noise from center
wx1 = 149.5-129;
wx2 = 165.5-129;
wy  = 157.5-129;

% create notch filter
filt = ones(m,n);

% use gaussian notch with standard deviation of 5
sigma = 5;
[y,x] = meshgrid(1:n, 1:m);
X = [y(:) x(:)].';
filt = filt .* reshape(gNotch(X,[cx+wx1;cy+wy],eye(2)*sigma^2),[m,n]);
filt = filt .* reshape(gNotch(X,[cx+wx2;cy+wy],eye(2)*sigma^2),[m,n]);
filt = filt .* reshape(gNotch(X,[cx-wx1;cy-wy],eye(2)*sigma^2),[m,n]);
filt = filt .* reshape(gNotch(X,[cx-wx2;cy-wy],eye(2)*sigma^2),[m,n]);

% apply filter
ft = ft .* filt;

% show spectrum after
figure();
show_spec(ft);

% compute inverse
ifft_ = ifft2(ifftshift( ft));
img_res = histeq(norm_img(ifft_));

figure();
imshow(img_res);

Edit: Swapped parameters for meshgrid for reason indicated by Todd Gillette.

like image 130
jodag Avatar answered Nov 10 '22 18:11

jodag


jodag's answer works well for me, except for a swapped m and n in the meshgrid command. It should be

    [y,x] = meshgrid(1:n, 1:m);

It worked in the example because the image is square, but with a rectangular image it does not work properly.

[I would have preferred to comment, but I don't yet have the reputation.]

like image 33
Todd Gillette Avatar answered Nov 10 '22 18:11

Todd Gillette