Say you have two arrays of numbers: \(I\) is the image and \(g\) is what we call the convolution kernel. They might look like

\[I= \left( \begin{array}{ccc} 255 & 7 & 3 \\ 212 & 240 & 4 \\ 218 & 216 & 230 \end{array}\right) \] and \[g= \left( \begin{array}{cc} -1 & 1 \end{array}\right). \] We define their convolution as \[ I' = \sum_{u,v}{I(x-u, y-v)\; g(u,v)}. \]

It means that you overlay at each position \((x, y)\) of \(I\) a mirror image of \(g\) looking backwards, so that its bottom right element is over the position of \(I\) you are considering; then you multiply overlapping numbers and put the sum of the results in the position \((x, y)\) of \(I'\). In the above example, \[ \left( \begin{array}{cccc} 1\cdot 0 & \mathbf{-1\cdot 255} & 7 & 3 \\ & 212 & 240 & 4 \\ & 218 & 216 & 230 \end{array}\right) \rightarrow \left( \begin{array}{ccc} \mathbf{-255} & 7 & 3 \\ 212 & 240 & 4 \\ 218 & 216 & 230 \end{array}\right), \] then \[ \left( \begin{array}{cccc} & 1\cdot 255 & \mathbf{-1 \cdot 7} & 3 \\ & 212 & 240 & 4 \\ & 218 & 216 & 230 \end{array}\right) \rightarrow \left( \begin{array}{ccc} -255 & \mathbf{248} & 3 \\ 212 & 240 & 4 \\ 218 & 216 & 230 \end{array}\right), \] \[ \left( \begin{array}{cccc} & 255 & 1 \cdot 7 & \mathbf{-1 \cdot 3} \\ & 212 & 240 & 4 \\ & 218 & 216 & 230 \end{array}\right) \rightarrow \left( \begin{array}{ccc} -255 & 248 & \mathbf{4} \\ 212 & 240 & 4 \\ 218 & 216 & 230 \end{array}\right), \] and then on the next row, \[ \left( \begin{array}{cccc} & 255 & 1 \cdot 7 & 3 \\ 1\cdot 0 & \mathbf{-1 \cdot 212} & 240 & 4 \\ & 218 & 216 & 230 \end{array}\right) \rightarrow \left( \begin{array}{ccc} -255 & 248 & 4 \\ \mathbf{-212} & 240 & 4 \\ 218 & 216 & 230 \end{array}\right). \] Note that we assume that the non-existing left neighbors of the first column are zero.

If \(g\) was two-dimensional, like \[g= \left( \begin{array}{cc} -1 & 1 \\ 2 & 3 \end{array}\right), \] we would mirror it in the two dimensions before overlaying, \[ \left( \begin{array}{cccc} 3 \cdot 0 & 2 \cdot 0 & & \\ 1\cdot 0 & \mathbf{-1\cdot 255} & 7 & 3 \\ & 212 & 240 & 4 \\ & 218 & 216 & 230 \end{array}\right). \]