# Help Understanding Convolution Filter Formulation

I'm reading Computer Vision: Algorithms and Applications wich is available online as a PDF and on Chapter 3.2 page 111 it introduces convolution operators for images giving the formulation:

$g(i, j) = \Sigma_{k,l} f(i − k, j − l)h(k, l) = \Sigma_{k,l}f(k, l)h(i − k, j − l)$

since $(i,j)$ are pixel coordinates $f$ is the pixel intensity function for the image we're convolving and $h$ is the function for the convolution matrix it makes sense to me that $g(i,j)$ is equal to the first sum expression but I can't wrap my head around how this is equivalent to the second sum expression. If someone could explain this I would really appreciate it.

• It's just a change of variables. You could replace k by e.g. k+5 or in this case i-k and the sum would be the same. You're just summing in a different order. – Niki Estner Jan 9 '13 at 7:34

Suppose that the original image is a single pixel of intensity $1$ at point $(0,0)$ and all other pixels have intensity $0$. Then, the result of the convolution of this image is $h(i,j)$, that is, this single pixel in the original image produces pixel intensity $h(i,j)$ at the point $(i,j)$. The actual image is a whole bunch of pixels, though, at different points, and the superposition principle says that the resulting pixel intensity $g(i,j)$ at point $(i,j)$ is the sum of of the pixel intensities produced by the various pixels in the original image. There are two ways of calculating $g(i,j)$. Let's go through the pixels in the original image in order of their distance from the point $(i,j)$. Well, the point $(i-k,j-l)$ is at distance $(k,l)$ from $(i,j)$ and the pixel intensity $f(i-k,j-l)$ there produces intensity $f(i-k,j-l)h(k,l)$ at $(i,j)$. This gives the first formula $$g(i,j) = \sum_k\sum_l f(i-k,j-l)h(k,l).$$ Alternatively, we can go through the pixels in natural order and ask what intensity the pixel $f(k,l)$ produces at the point $(i,j)$. Well, the distance is $(i-k,j-l)$ and so the intensity is $f(k,l)h(i-k,j-l)$ giving $$g(i,j) = \sum_k\sum_l f(k,l)h(i-k,j-l).$$