22

Could you please clearly explain what is the difference between correlation and convolution that is done by a filter on an image?

I mean in terms of signal processing definition I know that convolution describes the output of an LTI system, that is if an LTI system produces an output due to convolution with an input system then the output signal can be described as the result of convolution of the input signal and the impulse response of the LTI system. As for the correlation, it describes the similarities between to signals. But how does convolution and correlation effect on a image and how different are they in terms of effects?

Thanks

Royi
  • 19,608
  • 4
  • 197
  • 238
the_naive
  • 363
  • 1
  • 2
  • 7

1 Answers1

46

Convolution is correlation with the filter rotated 180 degrees. This makes no difference, if the filter is symmetric, like a Gaussian, or a Laplacian. But it makes a whole lot of difference, when the filter is not symmetric, like a derivative.

The reason we need convolution is that it is associative, while correlation, in general, is not. To see why this is true, remember that convolution is multiplication in the frequency domain, which is obviously associative. On the other hand, correlation in the frequency domain is multiplication by the complex conjugate, which is not associative.

The associativity of convolution is what allows you to "pre-convolve" the filters, so that you only need to convolve the image with a single filter. For example, let's say you have an image $f$, which you need to convolve with $g$ and then with $h$. $f * g * h = f * (g * h)$. That means you can convolve $g$ and $h$ first into a single filter, and then convolve $f$ with it. This is useful, if you need to convolve many images with $g$ and $h$. You can pre-compute $k = g * h$, and then reuse $k$ multple times.

So if you are doing template matching, i. e. looking for a single template, correlation is sufficient. But if you need to use multiple filters in succession, and you need to perform this operation on multiple images, it makes sense to convolve the multiple filters into a single filter ahead of time.

Dima
  • 5,101
  • 22
  • 28
  • Can you expand on the associativity of convolution VS correlation in this regard, if you wanted to filter an image with two different filters as an example? – TheGrapeBeyond Nov 16 '13 at 02:10
  • I've edited the answer. Is it clear now? – Dima Nov 16 '13 at 02:20
  • Yes Dima, thank you. So you are saying we cannot correlate $g$ and $h$ first and then correlate with $f$? – TheGrapeBeyond Nov 16 '13 at 05:30
  • @TheGrapeBeyond, that's right. Correlation is not associative. In the general case, when your filters are not symmetric, correlating $g$ and $h$ and then correlating the result with $f$ will not give you the same result as correlating $f$ with $g$ and then with $h$. – Dima Nov 16 '13 at 13:31
  • @Dima, thanks for the answer. Could you please further elaborate what do you mean by template matching? – the_naive Nov 16 '13 at 18:34
  • I have added a link to the answer. – Dima Nov 16 '13 at 20:10
  • I can bookmark the question, how can I bookmark the answer? – sergiol Nov 22 '17 at 19:30
  • @sergiol Bookmarking the question would seem sufficient, since there is only one answer so far... :) – Dima Nov 22 '17 at 19:42
  • Are the terms correlation and cross-correlation interchangeable in the context of image processing? – ado sar Feb 07 '24 at 14:29
  • @adosar, Generally, yes. However, there is normalized cross-correlation, which is different from correlation. – Dima Feb 12 '24 at 14:08