3
$\begingroup$

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

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

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
7
  • $\begingroup$ Can I choose x(k,l) to be the kernel as well? $\endgroup$
    – user8005
    Commented May 1, 2013 at 20:36
  • $\begingroup$ Yes, but then your data needs to be flipped. $\endgroup$
    – Matt L.
    Commented May 1, 2013 at 20:36
  • $\begingroup$ I forgot the benefit of the minussigns of h(-k, -l). I thought it was something with the fourier transforms? $\endgroup$
    – user8005
    Commented May 1, 2013 at 20:37
  • $\begingroup$ It's just how convolution/filtering works. Convolution in the time/spatial domain corresponds to multiplication in the frequency domain, but only if you define convolution properly. $\endgroup$
    – Matt L.
    Commented May 1, 2013 at 20:39
  • 1
    $\begingroup$ Are you the same user as in here: scicomp.stackexchange.com/questions/6962/… ? If not, please read the answer and comments in that question. $\endgroup$ Commented May 2, 2013 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.