Understanding Gaussian smoothing/filtering

  • Thread starter pamparana
  • Start date
  • Tags
    Gaussian
In summary, the conversation discusses the use of Gaussian smoothing and its application in 3D images. The first question is related to the scaling factor (1/273) in the discrete Gaussian kernel, which is used to ensure that the sum of the values is 1. The second question pertains to the placement of the scaling loop in the pseudocode, and it is determined that the sum of all rescaled values in the entire kernel should be 1. The conversation also touches on the normalization factor for the discrete kernel and its relationship with sigma = 1. It is noted that this factor is only universally valid for the continuous kernel, and for sigma < 1 and other kernels, it may not result in a sum of 1
  • #1
pamparana
128
0
Hello,

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

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

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?

Thanks,

Luca
 
Last edited by a moderator:
Mathematics news on Phys.org
  • #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.
 
  • #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.

Thanks,

Luca
 
  • #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.
 
  • #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.

Luca
 

1. What is Gaussian smoothing/filtering?

Gaussian smoothing/filtering is a technique used in signal processing and image processing to reduce noise and smooth out sharp transitions in data. It is based on the Gaussian function, which is a bell-shaped curve used to represent the probability distribution of a continuous variable.

2. How does Gaussian smoothing work?

Gaussian smoothing works by convolving a signal or image with a Gaussian kernel, which is a matrix of numbers that follows the shape of a Gaussian function. This kernel acts as a weighted average, giving more weight to data points near the center and less weight to those farther away. This results in a smoother version of the original signal or image.

3. What are the benefits of using Gaussian smoothing?

Gaussian smoothing has several benefits, including reducing noise, smoothing out sharp transitions, and preserving the overall shape and features of the original data. It is also a relatively simple and efficient technique that can be applied to a wide range of data types.

4. Are there any limitations to Gaussian smoothing?

While Gaussian smoothing is effective in reducing noise and smoothing data, it can also blur out small details and edges in an image or signal. This is because the Gaussian kernel gives more weight to data points near the center, causing a loss of sharpness in the data. Additionally, the amount of smoothing can be difficult to control, as it is dependent on the size and shape of the Gaussian kernel.

5. How is Gaussian smoothing used in real-world applications?

Gaussian smoothing is commonly used in a variety of fields, including image processing, computer vision, and data analysis. It is often used as a pre-processing step to improve the quality of data before applying other techniques, such as edge detection or feature extraction. It is also used in machine learning and artificial intelligence algorithms to reduce noise and improve the accuracy of predictions.

Similar threads

Replies
2
Views
1K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
949
  • Calculus and Beyond Homework Help
Replies
0
Views
117
  • Programming and Computer Science
Replies
4
Views
571
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • General Math
Replies
11
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
1
Views
1K
Back
Top