# Why can Sum of Squared Differences (SSD) seen as cross-correlation?

In this slides, on page 4, the SSD can be seen as cross-correlation:

The SSD is defined as:

$$SSD(m,n) = \sum_i \sum_j [g(i,j) - t(i-m,j-n)]^2,$$

and expand the SSD. It looks like this:

$$SSD(m,n) = \sum_i \sum_j [g(i,j)^2 + t(i-m,j-n)^2 - 2g(i,j)t(i-m,j-n)],$$

where the squared terms can be assumed as constant. As a result, the cross-correlation remains:

$$R(m,n)= \sum_i \sum_j [g(i,j) t(i-m, j-n)].$$

Question: Why can we assume that the squared terms are constant?

• well, for those of us in audio and speech processing, we've been calling this "ASDF" (for Average Squared Difference Function) and have only one dimension instead of two. but the reason for its relationship to autocorrelation is the same and shown in this answer from before. – robert bristow-johnson Mar 15 '19 at 0:55

The second term is constant because $$\sum_{i, j}t(i-m, j-n)^2$$ is simply the energy of the template and importantly does not depend on $$m$$ or $$n$$.
Assuming that $$\sum_{i, j}g(i,j)^2$$ is constant is equivalent to assuming that the energy in the section of the image that aligns with the template does not vary with the position of the template (dictated by $$m$$ and $$n$$). I am not quite sure why this is a valid assumption, perhaps someone else may be able to help here.
• For each $m$ and $n$ the template ends up over a different region in the image, which means that $g(i,j)t(i-m, j-n)$ differs for each $m$ and $n$. – Abraham Feb 13 '19 at 22:15
• @j35t3r Nobody is claiming that the squared terms don't individually depend on $m$ and $n$. What is being claimed is that the sum of the squared terms is a constant, I,e.. not dependent on $m$ and $n$. – Dilip Sarwate Mar 20 '19 at 13:56