In Image processing, one often uses the discrete Laplacian of Gaussian (LoG) to do edge detection with
$LoG(x,y) = -\frac{1}{\pi \sigma^4}[1-\frac{x^2+y^2}{2\sigma^2}]\cdot e^{-\frac{x^2+y^2}{2\sigma^2}}$
Various sources here, here or here give discrete Kernels of the LoG to be convoluted with the input image to yield the filtered version. However, I do not understand the derivation of this Kernel from the function.
One possible Kernel for $\sigma = 1.4$ is
$K = \begin{bmatrix}0.0& 1.0& 1.0& 2.0& 2.0& 2.0& 1.0& 1.0& 0.0\\
1.0& 2.0& 4.0& 5.0& 5.0& 5.0& 4.0& 2.0& 1.0\\
1.0& 4.0& 5.0& 3.0& 0.0& 3.0& 5.0& 4.0& 1.0\\
2.0& 5.0& 3.0& -12.0& -24.0& -12.0& 3.0& 5.0& 2.0\\
2.0& 5.0& 0.0& -24.0& -40.0& -24.0& 0.0& 5.0& 2.0\\
2.0& 5.0& 3.0& -12.0& -24.0& -12.0& 3.0& 5.0& 2.0\\
1.0& 4.0& 5.0& 3.0& 0.0& 3.0& 5.0& 4.0& 1.0\\
1.0& 2.0& 4.0& 5.0& 5.0& 5.0& 4.0& 2.0& 1.0\\
0.0& 1.0& 1.0& 2.0& 2.0& 2.0& 1.0& 1.0& 0.0\end{bmatrix}$
My question is, how these discrete Kernels are derived from the $LoG(x,y)$ function. Is there any scaling factor involved? Is it an integration over the discrete pixel area?
My calculated values for the central point (-40.0) are:
$LoG(0,0) \approx -0.1624$
and
$\iint\limits_{-0.5}^{0.5}{LoG(x,y)} dx dy \approx -0.0761$
Best Answer
The answer is scaling. The matrix $K$ is simply a $n\times n$ matrix with $n$ being odd and
$K(i,j)=LoG(i-\frac{n-1}{2},j-\frac{n-1}{2})$.
The whole matrix can be scaled for easier calculation in the integer range.
The following python code produces a matrix, that is "close enough" to the wanted output:
$K = \begin{bmatrix}0& 0& 1& 2& 2& 2& 1& 0& 0\\ 0& 1& 3& 5& 5& 5& 3& 1& 0\\ 1& 3& 5& 3& 0& 3& 5& 3& 1\\ 2& 5& 3&-12& -23& -12& 3& 5& 2\\ 2& 5& 0& -23& -40& -23& 0& 5& 2\\ 2& 5& 3&-12& -23& -12& 3& 5& 2\\ 1& 3& 5& 3& 0& 3& 5& 3& 1\\ 0& 1& 3& 5& 5& 5& 3& 1& 0\\ 0& 0& 1& 2& 2& 2& 1& 0& 0\end{bmatrix}$