# About Sum of Squared differences

I found a paragraph in the book about $SSD$, can't get one thing:

Most commonly, the distance measure is the sum of squared differences. For two images $f(x, y)$ and $g (x, y)$ it is defined as $$SSD(d_1,d_2) = \sum_{i=-n_1}^{n_1} \sum_{j=-n_2}^{n_2} \big(f(x+i,\,y+j)-g(x+i-d_1,\,y+j-d_2)\big)^2$$

where the summation extends over the region of size $(2n_1 + 1) \times (2n_2 + 1)$.

I can not get, why does $i$ changes from $-n_1$ to $n_1$, but not from $0$ to $n_1$. The similar about $j$. And why does summation goes over the $(2n_1 + 1) \times (2n_2 + 1)$ but not over the $(n_1) \times (n_2)$

-

## migrated from stackoverflow.comJun 22 '12 at 18:35

This question came from our site for professional and enthusiast programmers.

(0, 0) represents the pixel in question. In order to go both positive and negative in both axes it is required to use both strictly positive (e.g. n<sub>1</sub>) and strictly negative (e.g. -n<sub>1</sub>) offsets. – Ignacio Vazquez-Abrams Jun 21 '12 at 19:06
But in Matrix, there are no negative offsets oO – user1448906 Jun 21 '12 at 19:17
As defined, SSD(d1,d2) appears to be an image itself for each d1 and d2: It depends on x and y. This might be correct, but I am unsure. – willem Jun 21 '12 at 19:26
It seems that $(i, j)$ represents the offset from the point $(x, y)$. So, for example, $(i, j) = (0, 0)$ corresponds to the point $(x, y)$ itself. The collection of $(i, j)$ that you sum over forms a $2$-dimensional array (matrix if you like) that happens to be indexed where $(0, 0)$ is in the middle. This is okay and makes a lot of sense, given the context. You can define $k = i + n_1 + 1$ and see that it ranges from $1$ to $2n_1 + 1$ if you insist. Analogously, for $\ell = j + n_2 + 1$. – Sammy Black Dec 13 '13 at 22:01
because it is used for finding correlation...its similar to convolution...therefore consideration starts when the last pixel of first image is multiplied with the first pixel of the second image and continues till first pixel of the first image is multiplied with the last pixel of the second image... hint: refer to convolution (see esp overlapping technique) – user155823 Jun 7 '14 at 18:31