I'm having trouble calculating the same values for a Gaussian filter kernel as those derived in the Canny edge detector Wikipedia page
It states:
The equation for a Gaussian filter kernel of size (2k+1)x(2k+1) is given by:
$$ H_{i,j} = \frac {1} {2\pi\sigma^2} \exp\left(- \frac {(i - (k + 1))^2 + (j - (k + 1)^2} {2\sigma^2}\right) \\ ; 1 \le i, j \le (2k + 1) $$
Here is an example of a 5×5 Gaussian filter, used to create the adjacent image, with $\sigma = 1$. (The asterisk denotes a convolution operation.)
$$ \textbf{B} = \frac{1}{159} \begin{bmatrix} 2 & 4 & 5 & 4 & 2 \\ 4 & 9 & 12 & 9 & 4 \\ 5 & 12 & 15 & 12 & 5 \\ 4 & 9 & 12 & 9 & 4 \\ 2 & 4 & 5 & 4 & 2 \\ \end{bmatrix} * \textbf{A} $$
My work for just the first term:
For a 5x5 filter, I calculate k using the equation $2k+1 = 5$: $$ k = \frac{5 - 1}{2} \rightarrow k = 2 $$
The range for $i, j$ now becomes $1 \le i, j \le 5$
For $i, j = (1, 1)$ & $\sigma = 1$:
$$ \begin{align*} H_{1,1} &= \frac {1} {2\pi\cdot1^2} \exp\left(- \frac {(1 - (2 + 1))^2 + (1 - (2 + 1)^2} {2\cdot1^2}\right)\\ &= \frac {1} {2\pi} \exp\left(- \frac {(-2)^2 + (-2)^2} {2}\right)\\ &= \frac {1} {2\pi} \exp\left(-4\right)\\ &= (0.1592...) \cdot (0.0183...)\\ &\approx 0.0029\\ \end{align*} $$
Looking at the result from the Wiki page for the top left-most term, it's equal to $\frac{1}{159}\cdot2 \approx 0.0126$
Applying my method to calculate the entire kernel I get: $$ \begin{bmatrix} 0.0029 & 0.0131 & 0.0215 & 0.0131 & 0.0029 \\ 0.0131 & 0.0585 & 0.0965 & 0.0585 & 0.0131 \\ 0.0215 & 0.0965 & 0.1592 & 0.0965 & 0.0215 \\ 0.0131 & 0.0585 & 0.0965 & 0.0585 & 0.0131 \\ 0.0029 & 0.0131 & 0.0215 & 0.0131 & 0.0029 \\ \end{bmatrix} $$
The kernel on the Wiki page resolves to: $$ \begin{bmatrix} 0.0126 & 0.0252 & 0.0314 & 0.0252 & 0.0126 \\ 0.0252 & 0.0566 & 0.0755 & 0.0566 & 0.0252 \\ 0.0314 & 0.0755 & 0.0943 & 0.0755 & 0.0314 \\ 0.0252 & 0.0566 & 0.0755 & 0.0566 & 0.0252 \\ 0.0126 & 0.0252 & 0.0314 & 0.0252 & 0.0126 \\ \end{bmatrix} $$
Both results are rounded to 4 decimal places. Am I doing something wrong in my calculations? Looking at the more general equation:
$$ G(x,y) = \frac{1}{2\pi\sigma^2}e^{-\frac{x^2 + y^2}{2\sigma^2}} $$ where $x, y$ are the horizontal and vertical distances from the center of the kernel, respectively. In the example above, this is accounted for by the $(i - (k + 1))$ and $(j - (k + 1))$ terms. Yet, all other terms are fixed or constants, so there must be something wrong with my understanding of the $i, j, k$ variables.