找到合适的陷波滤波器以从图像中移除图案 [英] Find proper notch filter to remove pattern from image

查看:411
本文介绍了找到合适的陷波滤波器以从图像中移除图案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图像上应用陷波滤镜,它会抑制图像中的图案,但保留图像的其余部分尽可能完整。
我执行以下步骤:

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.

推荐答案

如果您查看图像的fft,您可以清楚地看到导致图像模式的强频率。

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.

ifft图像(对比度增强)原来是

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

以下是用于构建和应用过滤器的一些MATLAB代码

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

编辑: meshgrid 的交换参数托德吉列表示。

Swapped parameters for meshgrid for reason indicated by Todd Gillette.

这篇关于找到合适的陷波滤波器以从图像中移除图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆