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 :
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.
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.
The ifft image (with contrast enhanced) turns out to be
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.
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.]