推导图像卷积核的逆滤波器 [英] Deriving the Inverse Filter of Image Convolution Kernel

查看:116
本文介绍了推导图像卷积核的逆滤波器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何计算二维滤波器的逆数吗?

Does anyone has an idea how to calculate the Inverse of a 2-D filter?

假设我有一个3x3滤镜:
0 1 0
1 1 1
0 1 0
我想发现它是相反的. 使用DFT很容易做到. 但是,让我们说我想通过卷积来做到这一点. 现在,这就是问题,Matlab符号不是我的专长. 假设有一个3X3逆滤波器,则意味着两者的卷积将导致:
0 0 0
0 1 0
0 0 0
问题是为此创建正确的方程组并求解. 用符号做它很容易想到,但我做不到.

Let's say I have a 3x3 filter:
0 1 0
1 1 1
0 1 0
I want to find it's inverse. It's easy to do using DFT. But let's say I want to do it by convolution. Now, that's the problem, Matlab symbolic isn't my specialty. Assuming there's a 3X3 Inverse Filter it means convolution of the two will result in:
0 0 0
0 1 0
0 0 0
The problem is to create the right set of equations for that and solving it. Doing it with symbols is easy to think yet I couldn't do it.

有什么想法吗? 谢谢.

Any ideas? Thanks.

P.S. 我不确定这是一个逆滤波器,因为它的DTFT中有零.

P.S. I'm not sure there an Inverse Filter for this one as it has zeros in its DTFT.

此外,有人应该像MathOverflow一样允许乳胶进入该论坛.

Moreover, someone should allow Latex in this forum the way MathOverflow has.

推荐答案

推导给定2D卷积内核的逆内核

这基本上是问题的概括-推导图像卷积内核的逆滤波器.

给出卷积内核$ f \ in \ mathbb {R} ^ {m \ timesn} $找到其逆内核,$ g \ in \ mathbb {R} ^ {p \ times q} $这样$ f \ ast g = h = \ delta $.

Given a Convolution Kernel $ f \in \mathbb{R}^{m \times n} $ find its inverse kernel, $ g \in \mathbb{R}^{p \times q} $ such that $ f \ast g = h = \delta $.

可以构建卷积运算符的矩阵形式.
矩阵表单可以复制各种模式的图像过滤(独家):

One could build the Matrix Form of the Convolution Operator.
The Matrix form can replicate various mode of Image Filtering (Exclusive):

  • 边界条件(应用于填充图像并在有效模式下应用卷积).
    • 零填充 用零填充图像.
    • 圆形
      使用图像的循环/周期性延续. 匹配频域卷积.
    • 复制
      复制边缘值(最近的邻居).
      通常在现实世界中产生的文物最少.
    • 对称
      沿边缘镜像图像.
    • Boundary Conditions (Applied as padding the image and apply Convolution in Valid mode).
      • Zero Padding Padding the image with zeros.
      • Circular
        Using Circular / Periodic continuation of the image. Match Frequency Domain convolution.
      • Replicate
        Replicating the edge values (Nearest Neighbor).
        Usually creates the least artifacts in real world.
      • Symmetric
        Mirroring the image along the edges.
      • 满 输出大小是最大的-$ \ left(m + p-1 \ right)\ times \ left(n + q-1 \ right)$.
      • 相同
        输出大小与输入大小(图片")相同.
      • 有效
        输出大小是图像和内核完全重叠的大小.
      • Full The output size is to full extent - $ \left( m + p - 1 \right) \times \left( n + q - 1 \right) $.
      • Same
        Output size is the same as the input size ("Image").
      • Valid
        Output size is the size of full overlap of the image and kernel.

      使用图像过滤"时,输出大小与输入大小匹配,因此矩阵形式为正方形,并且定义了逆.
      使用卷积矩阵,矩阵可能不是正方形(除非选择相同"),因此应推导伪逆.

      When using Image Filtering the output size matches the input size hence the Matrix Form is square and the inverse is defined.
      Using Convolution Matrix the matrix might not be square (Unless "Same" is chosen) hence the Pseudo Inverse should be derived.

      应该注意的是,虽然输入矩阵应该是稀疏的,但逆矩阵却不是.
      此外,尽管卷积矩阵将具有特殊形式(Toeplitz忽略边界条件),但反之则不会.
      因此,此解决方案比下一个解决方案更准确,但同时也使用了更高的自由度(该解决方案不一定是Toeplitz形式).

      One should notice that while the input matrix should be sparse the inverse matrix isn't.
      Moreover while the Convolution Matrix will have special form (Toeplitz neglecting the Boundary Conditions) the inverse won't be.
      Hence this solution is more accurate than the next one yet it also use higher degree of freedom (The solution isn't necessarily in Toeplitz form).

      在此解决方案中,通过最小化以下成本函数得出逆:

      In this solution the inverse is derived using minimization of the following cost function:

      $$ \ arg \ min_ {g} \ frac {1} {2} {\ left \ | f \ ast g-h \ right \ |} _ {2} ^ {2} $$

      $$ \arg \min_{g} \frac{1}{2} {\left\| f \ast g - h \right\|}_{2}^{2} $$

      导数由:

      $$ \ frac {\ partial \ frac {1} {2} {\ left \ | f \ ast g-h \ right \ |} _ {2} ^ {2}} {\ partial g} = f \ star \ left(f \ ast g-h \ right)$$

      $$ \frac{\partial \frac{1}{2} {\left\| f \ast g - h \right\|}_{2}^{2} }{\partial g} = f \star \left( f \ast g - h \right) $$

      其中$ \ star $是Correlation运算.

      Where $ \star $ is the Correlation operation.

      在实践中,目标函数中的卷积是在full模式下完成的(MATLAB习惯用语).
      实际上,它是完成的:

      In practice the convolution in the Objective Function is done in full mode (MATLAB idiom).
      In practice it is done:

      hObjFun     = @(mG) 0.5 * sum((conv2(mF, mG, 'full') - mH) .^ 2, 'all');
      mObjFunGrad = conv2(conv2(mF, mG, 'full') - mH, mF(end:-1:1, end:-1:1), 'valid');
      

      代码将mF翻转为Correaltion并使用有效(矩阵形式为Adjoint/Transpose->输出较小).

      Where the code flips mF for Correaltion and use valid (In matrix form it is the Adjoint / Transpose -> the output is smaller).

      优化问题是严格凸的,可以使用Gradient Descent轻松解决:

      The optimization problem is Strictly Convex and can be solved easily using Gradient Descent:

      for ii = 1:numIteraions
          mObjFunGrad = conv2(conv2(mF, mG, 'full') - mH, mF(end:-1:1, end:-1:1), 'valid');
          mG          = mG - (stepSize * mObjFunGrad);
      end
      

      完整的代码可在我的 StackOverflow Q2080835 GitHub存储库中找到.

      Full code is available in my StackOverflow Q2080835 GitHub Repository.

      这篇关于推导图像卷积核的逆滤波器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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