使用偶数大小的内核进行图像卷积 [英] Image convolution with even-sized kernel

查看:343
本文介绍了使用偶数大小的内核进行图像卷积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个简单的2D图像卷积,但我的内核是偶数。我应该为我的内核中心选择哪些索引?我尝试使用Google搜索并查找现有代码。人们通常将内核集中在一起,因此在新的0之前会有一个样本。因此,如果我们有一个4x4内核,则居中的索引应该是 -2 -1 0 +1 。那是对的吗?如果是的话,为什么会这样呢?有人可以解释为什么 -2 -1 0 +1 是正确的,而 -1 0 +1 +2 不是?请记住,我想在不使用FFT的情况下执行卷积。

I want to perform a simple 2D image convolution but my kernel is even-sized. Which indices I should pick for my kernel center? I tried googling for an answer and looking existing codes. People usually center their kernel so there would be one sample more before the new 0. So, if we have a 4x4 kernel the centered indices should be -2 -1 0 +1. Is that correct? And if it is, why is that so? Can someone explain why -2 -1 0 +1 is correct while -1 0 +1 +2 is not? Keep in mind that I want to perform the convolution without using FFT.

推荐答案

如果我理解你的问题,那么对于偶数内核你是正确的,约定使内核居中,以便在新零之前还有一个样本。

If I understand your question correctly, then for even sized kernels you are correct that it is the convention to centre the kernel so that there is one more sample before the new zero.

所以,对于一个宽度为4的内核,如上所述,居中的索引将是 -2 -1 0 +1

So, for a kernel of width 4, the centred indices will be -2 -1 0 +1 as you say above.

然而,这实际上只是一个惯例 - 非对称卷积很少使用,不对称的确切性质(左/右等)与正确结果无关。我认为大多数实现都采用这种方式的原因是它们可以在给定相同输入的情况下给出可比较的结果。

However, this really is just a convention - an asymmetric convolution is very rarely used anyway and the exact nature of the asymmetry (to the left/right etc.) has no relation to the "correct" result. I would imagine that the reason that most implementations behave this way is so that they can give comparable results given the same inputs.

在频域中执行卷积时,无论如何,内核都被填充以匹配图像大小,并且您已经声明要在空间域中执行卷积。

When performing the convolution in the frequency domain, the kernel is padded to match the image size anyway, and you've already stated that you are performing the convolution in the spatial domain.

我更多对于为什么你需要首先使用偶数大小的内核感兴趣。

这篇关于使用偶数大小的内核进行图像卷积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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