计算2个图像之间的模糊内核 [英] Calculating the blur kernel between 2 images

查看:169
本文介绍了计算2个图像之间的模糊内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与标准(且更具挑战性)去模糊和超分辨率场景不同,我可以访问原始(清晰)图像 G ,并且模糊版本 B 。我只是在寻找模糊内核 h 。因为 B 是使用真实相机拍摄的,关系是:

Unlike the standard (and more challenging) de-blurring and super resolution scenarios, I have access to both the original (sharp) image G and it's blurred version B. I'm simply looking for the blur kernel h. So because B is taken using a real camera the relation is:

B = G * h + N     (其中 * 表示卷积, N 是一些加性噪音)

B=G*h+N     (where * denotes convolution and N is some additive noise)

当然,这是一个过度约束的问题,因为与 G 和<$相比, h 的规模较小c $ c> B 所以这对图像中的每几个像素都会在 h 的条目上生成一个等式。

Naturally, this is an over-constrained problem since h is small in size compared to G and B and so every few pixels in the pair of images generate an equation on the entries of h.

但实际实现这个的最简单方法是什么?到目前为止我的想法:

But what would be the simplest way to actually implement this? My thoughts so far:


  • 转到频域并进行划分(如这个答案建议)。但由于噪音正确,这在数值上会不可避免地不稳定吗?

  • 互相关 - 我只找到了1-D信号的例子,并且无法弄清楚如何使用二维图像情况。

  • 小心构建一个过度约束的线性系统 G'h'= B'寻找 h'这是使用某些优化过程的内核 h 条目的矢量版本。但这非常繁琐,矩阵 G'和vector B'的大小必然很大。

  • Moving to the frequency domain and doing division (as this answer suggests). But this would be inevitably numerically unstable because of the noise right?
  • Cross-correlation - I've only found examples for 1-D signals and couldn't figure out how to use in the 2D case of images.
  • Carefully constructing an over-constrained linear system G'h'=B' looking for h' which is a vector version of the entries of the kernel h using some optimization procedure. But this is very tedious and the matrix G' and vector B' are bound to be huge in size.

从C ++到MATLAB的任何编程语言的具体例子都非常有用。

A concrete example in any programming language from C++ to MATLAB would be extremely useful.

推荐答案

使用@ Shai的相关建议,我现在可以给出详细的答案。

Using @Shai's relevant suggestion, I can now give the detailed answer.

我建议的选项2和3是事实相同,显然是正确的方法。这也是由@Shai链接的建议论文的E步骤所做的。提出过度约束的问题实际上非常简单。

Options 2 and 3 that I suggested are in fact the same and are apparently the right way to go. It is also what was done in the E-step of the suggested paper linked by @Shai. Posing the over constrained problem is in fact quite simple.

为了正确地构造这些方程式,我们使用的事实是每个块的点积与内核的大小有关。 G 中的像素与 h 的180度旋转版本应该等于 B中的相应像素。这直接源于 B G 与卷积相关的事实,因此 G 通过互相关(因此180度旋转)与 B 中的像素相关。

To correctly pose these equations we use the fact that the dot product of every block the size of the kernel centered around some pixel in G with the 180 degrees rotated version of h should equal the corresponding pixel in B. This is directly derived from the fact that B and G are related by convolution and so blocks in G relate to pixels in B by cross-correlation (and hence the 180-degree rotation).

MATLAB代码现在变为:

The MATLAB code now becomes:

%inputs: B,G - gray level blurred and sharp images respectively (double)
%        szKer - 2 element vector specifying the size of the required kernel
%outputs: mKer - the recovered kernel, 
%         imBsynth - the sharp image convolved with the recovered kernel
%
%example usage:  mKer = calcKer(B, G, [11 11]);

function [mKer, imBsynth] = calcKer(B, G, szKer)

  %get the "valid" pixels from B (i.e. those that do not depend 
  %on zero-padding or a circular assumption
  imBvalid = B(ceil(szKer(1)/2):end-floor(szKer(1)/2), ...
      ceil(szKer(2)/2):end-floor(szKer(2)/2));

  %get a matrix where each row corresponds to a block from G 
  %the size of the kernel
  mGconv = im2col(G, szKer, 'sliding')';

  %solve the over-constrained system using MATLAB's backslash
  %to get a vector version of the cross-correlation kernel
  vXcorrKer = mGconv \ imBvalid(:);

  %reshape and rotate 180 degrees to get the convolution kernel
  mKer = rot90(reshape(vXcorrKer, szKer), 2);

  if (nargout > 1)
      %if there is indeed a convolution relationship between B and G
      %the following will result in an image similar to B
      imBsynth = conv2(G, mKer, 'valid');
  end

end

我还发现可能需要对解决方案施加一些限制对于实际场景。示例是强制内核为正,平滑或对称。合并这些的确切方法超出了这个问题的范围,但在求解 vXcorrKer 时,通常会以线性约束或正则化元素的形式出现。

I also found that some constraints over the solution may be necessary for practical scenarios. Examples are enforcing the kernel to be positive, smooth, or symmetric. The exact method of incorporating these is out of the scope of this question but will usually come in the shape of a linear constraint or a regularization element when solving for vXcorrKer.

这篇关于计算2个图像之间的模糊内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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