1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Understanding Gaussian smoothing/filtering

  1. Mar 18, 2010 #1

    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) {
    for (int j = -radius; j < radius; ++j) {// The kernel of a given radius...
    // Compute kernel value at the given point
    kernelSum += computed_kernel_value;
    for (int j = -radius; j < radius; ++j) {
    // 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?


    Last edited by a moderator: May 4, 2017
  2. jcsd
  3. Mar 19, 2010 #2
    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.
  4. Mar 19, 2010 #3
    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.


  5. Mar 19, 2010 #4
    The normalization factor in your link ([itex]1/\sqrt{2\pi}\sigma[/itex]) 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:

    [tex]\sum_{n=-\infty}^\infty G(n) = 1[/tex]

    But for sigma<1 and for other kernels, that is no longer the case.
  6. Mar 19, 2010 #5
    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.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook