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)$