DSPRelated.com
Forums

Gaussian Filtering

Started by Michel Rouzic January 17, 2007
I've read a lot of documentation about gaussian filtering/interpolation
but I can't help but to still be confused, I mean I don't know how to
do it.

Right now what I'm trying to do is to implement a vector graphics
rendering engine that would calculate the value for each pixel based on
the distance of this pixel to the closest point on the line currently
being rendered, and looking up this distance on a look-up table
generated with the function of my choice (I chose the gaussian
function, seemed like an obvious choice, the sinc function didn't sound
like a good idea considered its ripples and negative values), but I'll
need to understand what I'm trying to figure out with other things.

So, let's take as an example interpolation of a discrete signal, if I
generate my gaussian function with exp(-pi * t^2) (one thing that
confused me about the gaussian function is the diversity of formulas
used to generate it, but this one sounds right), how much space between
each samples should I have (like 0.5? 1.0? something else?), and
secondly, how should I do in order to limit the length of the function
so that it doesn't go further than 2 samples back and 2 samples ahead,
should I window it with a Blackman function?

Thanks in advance.

Michel Rouzic wrote:
> I've read a lot of documentation about gaussian filtering/interpolation > but I can't help but to still be confused, I mean I don't know how to > do it. > > Right now what I'm trying to do is to implement a vector graphics > rendering engine that would calculate the value for each pixel based on > the distance of this pixel to the closest point on the line currently > being rendered, and looking up this distance on a look-up table > generated with the function of my choice (I chose the gaussian > function, seemed like an obvious choice, the sinc function didn't sound > like a good idea considered its ripples and negative values), but I'll > need to understand what I'm trying to figure out with other things. > > So, let's take as an example interpolation of a discrete signal, if I > generate my gaussian function with exp(-pi * t^2) (one thing that > confused me about the gaussian function is the diversity of formulas > used to generate it, but this one sounds right), how much space between > each samples should I have (like 0.5? 1.0? something else?), and > secondly, how should I do in order to limit the length of the function > so that it doesn't go further than 2 samples back and 2 samples ahead, > should I window it with a Blackman function? > > Thanks in advance.
Interpolation in general involves the calculation of new samples as weighted values of other samples in the area. The weighting function and the number of neighboring samples used are what differentiate interpolation methods from each other. In one dimension, you can interpolate by inserting zero samples throughout the signal, then convolving with the weighting sequence; the same idea extends to two dimensions for image processing also. Gaussian interpolation, as you said, uses a Gaussian function to weight the adjacent samples. The variance of the Gaussian curve that you use, however, is a degree of freedom; small variance will yield interpolation using mostly the samples directly adjacent to the one being interpolated; large variance will use more samples to calculate the interpolated value. To save on calculations, you could window the Gaussian function appropriately, but the window length you would want to use would depend on the variance; you only want to chop off the tails of the Gaussian function, which won't add much to the output anyway. Another note: after interpolation, you should probably normalize the intensity of the newly-interpolated sample to some function of its neighbors; the nonlinear nature of the Gaussian weight function can result in the interpolant to have higher intensity than the samples you interpolated it with, which would look wrong. Jason

Michel Rouzic wrote:
> > I've read a lot of documentation about gaussian filtering/interpolation > but I can't help but to still be confused, I mean I don't know how to > do it. > > Right now what I'm trying to do is to implement a vector graphics > rendering engine that would calculate the value for each pixel based on > the distance of this pixel to the closest point on the line currently > being rendered, and looking up this distance on a look-up table > generated with the function of my choice (I chose the gaussian > function, seemed like an obvious choice, the sinc function didn't sound > like a good idea considered its ripples and negative values), but I'll > need to understand what I'm trying to figure out with other things. > > So, let's take as an example interpolation of a discrete signal, if I > generate my gaussian function with exp(-pi * t^2) (one thing that > confused me about the gaussian function is the diversity of formulas > used to generate it, but this one sounds right), how much space between > each samples should I have (like 0.5? 1.0? something else?), and > secondly, how should I do in order to limit the length of the function > so that it doesn't go further than 2 samples back and 2 samples ahead, > should I window it with a Blackman function? >
You are drawing anti-aliased lines, No? You don't want a gaussian function since that extends to infinity. You want a function that fits a description something like this: The input is the distance from the line being drawn, and the output goes from one when the distance is zero to zero when the distance is 2 (your Max distance). And you want the function to be a nice S-shaped curve (bell-shaped when generated in both directions). You could derive this function from a properly scaled and windowed gaussian function, but it would be simpler and computationally faster to simply use a cubic function. For instance z =(8 -6d^2 + 2d^3)/8 where d is the distance from the line and any distance greater than 2 would return zero. -jim ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
jim wrote:
> You are drawing anti-aliased lines, No?
Exactly
> You don't want a gaussian function since that extends to infinity.
That's why I suggested windowing. It won't really extend to infinity anyways considered the color depth I'll be using.
> You could derive > this function from a properly scaled and windowed gaussian function, but > it would be simpler and computationally faster to simply use a cubic > function.
No thanks, for two reasons. Firstly, as I mentionned, I would use a look-up table, so it couldn't be more computationally efficient, and won't even hog up memory since it would be a 1D look-up table. Secondly, gaussian > cubic spline.
cincydsp@gmail.com wrote:
> Gaussian interpolation, as you said, uses a Gaussian function to weight > the adjacent samples. The variance of the Gaussian curve that you use, > however, is a degree of freedom; small variance will yield > interpolation using mostly the samples directly adjacent to the one > being interpolated; large variance will use more samples to calculate > the interpolated value.
Does variance have any impact on the shape of the gaussian function or does it only affect the scale? And how do I find what the variance is for exp(-pi * t^2)?
> To save on calculations, you could window the > Gaussian function appropriately, but the window length you would want > to use would depend on the variance
Of course, but would the windowing affect the variance?
> you only want to chop off the > tails of the Gaussian function, which won't add much to the output > anyway.
Well I guess I could do that, just wondering tho, wouldn't it be better to chop the tails off and then to substract to every bin the value of the last one? In case what I mean is not clear for example you would chop off the tails when the value of the function is around say 0.04, then wouldn't it be better to take 0.04 off to the whole of the function so that the function really starts and end at 0?
Michel Rouzic wrote:
> Does variance have any impact on the shape of the gaussian function or > does it only affect the scale? And how do I find what the variance is > for exp(-pi * t^2)?
It affects both. The general formula for a Gaussian function is: f(z) = 1/sqrt(2*pi*sigma^2) * exp( (z - m)^2 / (2*sigma^2)) where m is the mean of the Gaussian distribution described by the curve (stated differently, m is the value of z where the curve peaks) and sigma is the standard deviation (sigma^2 is called the variance) of the distribution. So, variance affects the whole shape of the curve; small variance gives you a narrow, tall function, and vice versa.
> Of course, but would the windowing affect the variance?
The variance is a parameter of the original curve; sure, once you window it, the curve is no longer Gaussian. The whole purpose of windowing in this case is to just discard the tails of the curve that don't contribute much to the output (you can't interpolate using an infinite number of inputs, obviously).
> > you only want to chop off the > > tails of the Gaussian function, which won't add much to the output > > anyway. > > Well I guess I could do that, just wondering tho, wouldn't it be better > to chop the tails off and then to substract to every bin the value of > the last one? In case what I mean is not clear for example you would > chop off the tails when the value of the function is around say 0.04, > then wouldn't it be better to take 0.04 off to the whole of the > function so that the function really starts and end at 0?
I wouldn't say it would be "better." By subtracting off the endpoint values, you're basically discarding an extra sample on either end of the one you're interpolating. That just has the effect of using a narrower window. If I were you, I wouldn't worry about using "fancy" windows; just use a rectangular window and use enough samples so that you're satisfied with the contribution they're making to the output. Jason