【问题标题】:filter detection过滤器检测
【发布时间】:2012-04-01 11:58:03
【问题描述】:

我必须确定,在随机图片上使用了哪个过滤器 - 是否有一种常用的方法来检测正确的过滤器(高斯、prewitt、sobel、平均......)或者编写某种代码是否聪明'蛮力'-检测?

我试图用 Matlab 找到它,但我不知道如何更更有效地搜索。目前,这就像在干草堆中找到一根针。我也想过使用一些 bash-script 和 imagemagick,但这会消耗资源。

我认为这不是问题,但猜测过滤器并像这样尝试非常耗时

f = fspecial('gaussian', [3 3], 1);
res = imfilter(orginal, f);
corr2(res, pic);

【问题讨论】:

  • 如果您有过滤后的图像和原始图像,那么确定过滤器系数非常简单,然后您就可以对过滤器内核进行分类。
  • 是的,我两者都有,但是如何确定系数?用matlab?
  • 您可以通过对两个图像进行 FFT、除法然后对结果进行逆 FFT 来反卷积。参见例如mathworks.com/matlabcentral/fileexchange/…
  • 好吧,这听起来不错,但过滤器内核是一个矩阵,但我收到 3 个值(1.0094、1.0046、1.0140)(系数?) - 我预计 25 [5x5] 或至少 9 [ 3x3]。如何获得卷积核?
  • @PaulR:如果图像有光谱零点,那在数值上就不是很稳定。

标签: matlab image-processing filter imagemagick gaussian


【解决方案1】:

f为原始图像,g为过滤后的图像,hf应用的过滤器>,因此:

f * h = g

将其传递到频域:

F.H = G, so H = G/F

问题在于反相 F 对噪声非常敏感。

如何在 MATLAB 中实现:

close all;
f = imread('cameraman.tif');
[x,y] = size(f);
figure,imshow(f);
h = fspecial('motion', 20, 40); % abitrary filter just for testing the algorithm
F = fft2(f);
H = fft2(h,x,y);
G = F.*H;
g = ifft2(G); % the filtered image
figure, imshow(g/max(g(:)));
% Inverting the original image
epsilon = 10^(-10);
small_values = find(abs(F)<epsilon);
F(small_values) = epsilon;
F_i = ones(x,y)./F;
H_calculated = G.*F_i;

h_calculated = ifft2(H_calculated);

% remove really small values to try to infer the original size of h
r = sum(h_calculated,1)<epsilon;
c = sum(h_calculated,2)<epsilon;
h_real = h_calculated(~r,~c);

% Calculate error
% redo the filtering with the found filter
figure,g_comp = ifft2(fft2(f).*fft2(h_real,x,y));
imshow(g_comp/max(g_comp(:)));
rmse = sqrt(mean(mean((double(g_comp) - double(g)).^2,2),1))

编辑:只是为了解释 epsilon 部分:

F 中的某些值可能为零,或非常接近于零。如果我们试图用这些小值反转 F,我们就会遇到无穷大的问题。解决这个问题的简单方法是截断 F 中小于任意小限制的每个值,即代码上的 epsilon。

在数学上,所做的是这样的:

For all F < epsilon, F = epsilon

【讨论】:

  • 它对光谱零点也非常敏感。
  • 是的,我知道,这就是我截断它的原因。对我来说,这种方法的真正问题是噪音。但总比没有好...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-27
  • 1970-01-01
  • 2018-04-05
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
  • 2012-04-02
相关资源
最近更新 更多