Image convolution with even-sized kernel

AstrOne picture AstrOne · Jun 11, 2013 · Viewed 11.6k times · Source

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.

Answer

Roger Rowland picture Roger Rowland · Jun 11, 2013

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.

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.

I'm much more intrigued as to why you need to use an even sized kernel in the first place.