I was reading about the 2D Gaussian-blur convolution kernel. A Gaussian vector is a vector where the elements follow a Gaussian distribution. In my case, the kernel is symmetric and hence we take a dyadic product (outer product) of the Gaussian vector to obtain the kernel for 2D. A sample Gaussian kernel implementation obtained from here is:
import numpy as np
def gkern(l=5, sig=1.):
"""
creates gaussian kernel with side length `l` and a sigma of `sig`
"""
ax = np.linspace(-(l - 1) / 2., (l - 1) / 2., l)
gauss = np.exp(-0.5 * np.square(ax) / np.square(sig))
kernel = np.outer(gauss, gauss)
return kernel / np.sum(kernel)
It can be noted that at the end of the kernel computation, we normalize the matrix using the total sum of the kernel elements.
I understand the point that we are using a normalized matrix to enforce some form of conservation(?) This being the case, is the dyadic product of a normalized Gaussian vector same as computing Gaussian matrix and dividing it by the sum as in above? A simple evaluation showed that the normalization factor is (a^2+b^2+c^2)
against (a+b+c)^2
for the first and second method respectively. Can anyone help me understand why we are doing total sum of the matrix for this normalization and also difference between the two normalization approaches?