22
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ what is the similarity between convolution and filter? $\endgroup$
    – user19395
    Feb 4, 2016 at 9:57

1 Answer 1

46
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ 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? $\endgroup$ Nov 16, 2013 at 2:10
  • $\begingroup$ I've edited the answer. Is it clear now? $\endgroup$
    – Dima
    Nov 16, 2013 at 2:20
  • $\begingroup$ Yes Dima, thank you. So you are saying we cannot correlate $g$ and $h$ first and then correlate with $f$? $\endgroup$ Nov 16, 2013 at 5:30
  • $\begingroup$ @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$. $\endgroup$
    – Dima
    Nov 16, 2013 at 13:31
  • $\begingroup$ @Dima, thanks for the answer. Could you please further elaborate what do you mean by template matching? $\endgroup$
    – the_naive
    Nov 16, 2013 at 18:34

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