0

I am learning image processing, and everywhere people say that "convolution is commutative but correlation is not." (For example, see slides 19, 24, & 25 here) However, after searching I cannot find a good example that correlation is not commutative. In fact, it seems commutative to me.

Here's a simple 1-D example. If I have:

F = [1 2 3] H = [1 2 3 4 5 6 7 8 9]

Then F corr H would be:

[14 20 26 32 38 44 50]

(first element is 1x1 + 2x2 + 3x3 = 14, second element is 1x2 + 2x3 + 3x4 = 20, and so on.

And if I compute H corr F, it seems like I get the same array.

Can someone provide a simple example that shows that correlation is not commutative?

I tried searching online for different lecture PDFs, trying my own examples by hand and even asking Chat GPT. None were able to clearly explain why correlation isn't a commutative operation.

Zeus Kim
  • 1
  • 1
  • This seems more suitable for https://dsp.stackexchange.com/ . It's not about programming, so doesn't belong here. Still, pay attention to how the correlation is computed, and which array you shift over the other when computing. – Cris Luengo Apr 17 '23 at 18:53
  • Thank you. I think I ended up figuring it out while writing my dsp stackexchange question, so just posted an answer here. – Zeus Kim Apr 17 '23 at 19:15

1 Answers1

0

Ok, I think I worked out an example. Posting here in case anyone has a similar question in the future:

Let's use these two simple arrays:

F = [1 0 -1]

H = [3 1 4 1 5 9]

I'll compute F convolution H, H convolution F, F correlation H and H correlation F.

F convolution H = [3 1 1 0 1 8 -5 -9]

This is computed by sliding reverse F over H, padding H with 0's is needed for the first 2 terms. For example:

  • The first term is: -1 * 0 + 0 * 0 + 1 * 3 = 3
  • The second term is: -1 * 0 + 0 * 3 + 1 * 1 = 1
  • The third term is: -1 * 3 + 0 * 0 + 1 * 4 = 1, and so on

(Sliding reverse F over H) H convolution F: [3 1 1 0 1 8 -5 -9]

  • The first term is 9 * 0 + 5 * 0 + 1 * 0 + 4 * 0 + 1 * 0 + 3 * 1 = 3.
  • The second term is 9 * 0 + 5 * 0 + 1 * 0 + 4 * 0 + 1 * 1 + 3 * 0 = 1, and so on

In a simliar, way, we can compute: F corr H: [-3 -1 -1 0 -1 -8 5 9]

This was done by sliding F over H. Finally, if we slide H over F, we get:

H corr F: [9 5 -8 -1 0 -1 -1 -3]

So we see that F convolution H is equal to H convolution F, but F corr H is not equal to H corr F. So convolution is associative but correlation is not.

Zeus Kim
  • 1
  • 1