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

1. 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"

songho (place-dot-here) ca/dsp/convolution/convolution2d_example.html  2.

3. Originally Posted by JonMuchnick songho (place-dot-here) ca/dsp/convolution/convolution2d_example.html
For the copy-pastey challenged:Example of 2D Convolution  4. Follow the link that says, "The definition of 2D convolution and the method how to convolve in 2D are explained here"

That explains why.  5. please explain in detail:

Notice that the kernel matrix is flipped both horizontal and vertical direction before multiplying the overlapped input data, becausex[0,0] is multiplied by the last sample of impulse response,h[1,1]. And x[2,2] is multiplied by the first sample, h[-1,-1].  6. Look at the definition of the convolution function just above that and, in particular, which elements are multiplied by which as a result of that definition. ("For example, x[0, 0] is x[0, 0]·δ[m, n], x[1, 2] is x[1, 2]·δ[m-1, n-2], and so on.") Work through this by hand and you should see that performing that sequence of operations is equivalent to flipping the kernel.  7. Originally Posted by Strange Look at the definition of the convolution function just above that and, in particular, which elements are multiplied by which as a result of that definition. ("For example, x[0, 0] is x[0, 0]·δ[m, n], x[1, 2] is x[1, 2]·δ[m-1, n-2], and so on.") Work through this by hand and you should see that performing that sequence of operations is equivalent to flipping the kernel.
Why do we use convolution for image processing in the first place? Doesn't flipping the kernel all the time, simply take more calculations and make it more complicated than not flipping the kernel each time? So, why did people decide to use convolution (so, to use the flipping by definition) for image processing?  8. Originally Posted by JonMuchnick Why do we use convolution for image processing in the first place?
Because it can be used for a large number of filtering and analysis tasks. (But you tell us: you are the one studying them! )

Doesn't flipping the kernel all the time, simply take more calculations and make it more complicated than not flipping the kernel each time?
It only ever has to be done once. And moving data around, or just changing the way it is indexed, costs very little compared to the thousands or billions of multiplies and adds that are performed when applying a filter to an image.  9. Oh, and btw. Didn't the flipping had something to do with the Fourier transforms and the convolution theorem?  Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement