# Understanding Gaussian smoothing/filtering

## Main Question or Discussion Point

Hello,

I was looking at the explanation for Gaussian smoothing found here:

http://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm" [Broken]

Now, figure 3 shows a discrete Gaussian kernel approximation. I have 2 questions:

1: Why is there a scaling factor (1/273)? Is it so that the sum of the discrete values is 1. I remember reading somewhere that the area under the Guassian curve is supposed to be 1. Is this also true in more than one dimension?

2: This is a more practical question. I am looking at some source code which attempts to smooth a 3D image using the separable technique and smoothes along each axes separately. So, it does it as follows:

float kernelSum = 0.0;
for (int i = 0; i < 3; ++i) {
// Compute kernel value at the given point
......
kernelSum += computed_kernel_value;
}
// Scale all kernel values in current axes by kernelSum
}
}

Now, my question is shouldn't it be scaling the kernel after it has computed the values in all 3 dimensions? Right now, it scales each axes by the sum of the kernel values along that axes. This ensures that the sum of the values along a particular axes is 1. However, shouldn't the sum along all the axes be equal to 1?

To be clear, should the scaling loop in the above pseudish-code be outside the main loop?

I hope the second bit of the code is clear? I think the question reduces to whether the area under the curve along each dimension is 1 or the whole curve (in all dimensions) has an area of 1 under it?

Thanks,

Luca

Last edited by a moderator:

Yes, the sum of all rescaled values in the entire kernel should be 1. That way, if you apply the kernel to a constant image, it's unchanged. If you do smoothing along each axis separately, the sum of kernel values in each 1-D kernel should be 1.

It's not 100% clear what's going on in that code. Depends on the way kernel values are computed. It is quite possible that kernel values don't add to 1 simply because of the windowing and the discretization: you'd get the right answer if you integrated from -infinity to +infinity, but instead you're summing from -radius to radius-1.

Thanks for the reply. I think I understand now. The isotropic Gaussian smoothing reduces to smoothing separately by Gaussian kernels in each of the dimensions and this is why the code was summing up the kernel coefficients for each axes and normalizing by that.

I guess if our discrete kernel is wide enough (3 standard deviations or moe), we do not need to bother with that as the sum will be sufficiently close to unity.

Thanks,

Luca

The normalization factor in your link ($1/\sqrt{2\pi}\sigma$) is only universally valid for the continuous kernel. It is a convenient curious fact that the same factor also works for the discrete kernel as long as sigma>=1:

$$\sum_{n=-\infty}^\infty G(n) = 1$$

But for sigma<1 and for other kernels, that is no longer the case.

That is indeed something that is not immediately clear to me.

I can appreciate that when sampling the continuous function to get the discrete values, the sum of the values will not be 1. However, I do not see anything else besides this...

How did you figure out the normalization factor and its special relationship with sigma = 1...?

Thanks for your replies. Much appreciated.

Luca