From: Luca on
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
From: Tim Wescott on
Luca wrote:
> 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?

By definition, yes. The Gaussian curve is a probability density, which
must integrate to one.

Here they just want a decent low-pass filter, so they're (I assume)
aiming for a DC gain of 1, which happens when the sum of the discrete
values is 1.

(I didn't actually sum the 25 numbers -- feel free to check to see if
they add up to 273).

> 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?

Try doing the math -- calculate the effective 2D kernel that you get
from a 1D kernel, and see what the sum is.

>
> 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


--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com
From: Luca on
> Try doing the math -- calculate the effective 2D kernel that you get
> from a 1D kernel, and see what the sum is.

Thanks for the reply. Yes, it seems that it is basically equivalant to
filtering along each axes by a separate Gaussian kernel, each with
unit area under the curve...

Thanks,

Luca
From: Jerry Avins on
Luca wrote:
>> Try doing the math -- calculate the effective 2D kernel that you get
>> from a 1D kernel, and see what the sum is.
>
> Thanks for the reply. Yes, it seems that it is basically equivalant to
> filtering along each axes by a separate Gaussian kernel, each with
> unit area under the curve...

That is why Gaussians are separable. BTW, "axes" is the plural of the
singular "axis".

Jerry
--
Discovery consists of seeing what everybody has seen, and thinking what
nobody has thought. .. Albert Szent-Gyorgi
�����������������������������������������������������������������������
From: jim on


Luca wrote:
>
> > Try doing the math -- calculate the effective 2D kernel that you get
> > from a 1D kernel, and see what the sum is.
>
> Thanks for the reply. Yes, it seems that it is basically equivalant to
> filtering along each axes by a separate Gaussian kernel, each with
> unit area under the curve...


But that is not correct. The 2d filter shown is not separable into 1d
filters. the only reasonably efficient way to execute the integer
coefficients shown in fig. 3 on that web page would be as a 2d kernel.
If you were to run the 1d kernel [1 4 7 4 1] in both X and Y you would
need to divide the result by 289 (17^2).

Often the coefficients derived from "Pascal's triangle" are
used when generating a Gaussian blur as separate 1d filters.
That would mean the length five 1d kernel would be {1 4 6 4 1] and the
normalization factor would be 1/256.

http://en.wikipedia.org/wiki/Pascal's_triangle


-jim