When should the sum of all elements of a gaussian kernel be zero? I found an approximation of a 5x5 2D convolution kernel like this :



Here, the sum of the elements is zero and this one was used for Laplacian of Gaussian!

Another one here :



This one has all positive and the sum is not zero and is being used for smoothing.

Could anyone please tell me what is with the sum being zero in the previous case ?

References:

Link1 and  Link2
The sum of a gaussian kernel cannot be zero, because all the elements are going to be positive. The first kernel you have shown, is most likely an edge detection kernel, (which is a type of high pass filter), so the elements add up to zero because you want to completely null out any DC/constant component. 

The second kernel you have shown however, is a low pass kernel, indeed used in smoothing. Here the elements are not going to add up to zero because you are not trying to remove the 'constant' part of the image, in fact, you are trying to remove any high frequency noise. 

Hope that helps.