# Why do we need to flip the kernel in 2D convolution?

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

• 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 1, 2013 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? May 1, 2013 at 20:03
• 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 1, 2013 at 20:09
• I agree with Peter K. "Flipping the kernel" is just part of the definition of convolution, no matter in how many dimensions. May 1, 2013 at 20:29
• Duplicate of scicomp.stackexchange.com/questions/6962/… which I already answered. I gave 1D as an example but can update to nD if required. May 2, 2013 at 2:43

$$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.