3

Why do we need to flip the kernel in 2D convolution in the first place? What's the benefit of this? So, why can't we leave it unflipped? What kind of terrible thing can happen if you don't flip it?

SEE: "First, flip the kernel, which is the shaded box, in both horizontal and vertical direction"

http://www.songho.ca/dsp/convolution/convolution2d_example.html

user8005
  • 133
  • 2
  • 9
  • 3
    I'm tempted to say that this is a duplicate of this question, however that one doesn't address 2D convolution. Let's see what others say. – Peter K. May 01 '13 at 19:53
  • If that would be a relevant answer, then how would 'scaled and time-delayed versions of the impulse response, not the "flipped"' make sense here? – user8005 May 01 '13 at 20:03
  • 2
    Because both questions are the same. One just uses a two dimensional "impulse response" rather than a one dimensional impulse response. Both are trying to understand how convolution works. – Peter K. May 01 '13 at 20:09
  • 1
    I agree with Peter K. "Flipping the kernel" is just part of the definition of convolution, no matter in how many dimensions. – Matt L. May 01 '13 at 20:29
  • 1
    Duplicate of http://scicomp.stackexchange.com/questions/6962/flipping-the-kernel-in-2d-convolution which I already answered. I gave 1D as an example but can update to nD if required. – geometrikal May 02 '13 at 02:43
  • Convolution is commutative in contrast to cross-correlation (unflipped kernel). That is of course not the whole reason, but could be a motivationl – olejorgenb Jan 23 '17 at 11:46

1 Answers1

2

At the risk of repeating what has been said elsewhere, this is how convolution in two dimensions is defined:

$$y(n_1,n_2) = \sum_{k}\sum_{l}x(k,l)h(n_1-k,n_2-l))$$

$x(n_1,n_2)$ is your data and $h(n_1,n_2)$ is the kernel. Note that in order to compute the double sum above, you need to flip $h(n_1,n_2)$ with respect to $x(n_1,n_2)$. Just take $n_1=0$ and $n_2=0$: in this case you need to multiply $x(k,l)$ with the flipped kernel $h(-k,-l)$. In order to compute the output for other values of $n_1$ and $n_2$ you need to move the flipped kernel across the input data.

Matt L.
  • 89,963
  • 9
  • 79
  • 179