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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jonmuchnick
Posts: 1
Joined: 2013-05-01T13:56:02-07:00
Authentication code: 6789

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

Post by jonmuchnick »

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?
You can include the convolution theorem in you answer ;)

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

http://www.songho.ca/dsp/convolution/co ... ample.html
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

This post and my reply should be moved to the User's forum.

The answer is that convolution and correlation are 180 rotations for the kernel from each other as Anthony correctly points out at http://www.imagemagick.org/Usage/convol ... _correlate. A convolution detect the same shape in a point image. A correlation will rotate that shape. See Anthony's examples at the link above.

However, for a symmetric kernel, the rotation makes no difference.

For non-symmetric kernels such as the sobel directional derivative convolution of

-1 0 1
-1 0 1
-1 0 1

the correlation with the same kernel will produce different edge image results. However, the correlation will produce the same result as the convolution if you rotate the kernel 180 degrees to

1 0 -1
1 0 -1
1 0 -1
Post Reply