I am writing a Gaussian blur filter in graphics shader code. I want to make the blur parameterized by radius from the users perspective. The best method I can figure to do this is to pick a suitable stopping point for y, say .001, and solve for the variance to plug into the normal distribution function that will achieve that value of y.

Unfortunately I cannot for the life of me solve this equation for v...

$x = 10$ (blur radius)

$$.001 = \frac{1}{2 \pi v^2}e^{-\frac{x^2}{2v^2}}$$.

  • 1
    $\begingroup$ I have tried to convert to latex (which you can do by enclosing in $ signs), so if things aren't what you expect, let me know. $\endgroup$ – Aryabhata Sep 4 '10 at 19:42
  • 1
    $\begingroup$ It looks like there is a typo here. If this is supposed to be the probability density function for an isotropic binormal distribution in 2d and $x$ is the radial coordinate, then it needs to be multiplied by $x$. (This won't change the solution methods already proposed, but it affects the details.) A few Newton-Raphson iterations should suffice to find the solution quickly. $\endgroup$ – whuber Sep 15 '10 at 3:26

To expand on the suggestion to use the Lambert function, I'll show how it arises in your equation of interest.

Starting with

$y=\frac1{2\pi v^2}\exp\left(-\frac{x^2}{2v^2}\right)$

we multiply both sides by $-\pi x^2$ to give

$-\pi x^2 y=-\frac{x^2}{2v^2}\exp\left(-\frac{x^2}{2v^2}\right)$

which can now be inverted to the Lambert function (recall that the Lambert function $W(z)$ is the inverse function of $z\exp(z)$, $W(z)\exp(W(z))=z$):

$-\frac{x^2}{2v^2}=W(-\pi x^2 y)$

which we can now solve for $v$

$v=\frac{x}{\sqrt{-2W(-\pi x^2 y)}}$

The choice of sign for the square root is motivated by the fact that variances are conventionally taken to be positive.

| cite | improve this answer | |
  • $\begingroup$ +1. I suggest you add a brief explanation of the Lambert function. I will delete my answer. $\endgroup$ – Aryabhata Sep 5 '10 at 22:49
  • $\begingroup$ Moron: Done, hopefully the one line explanation of the Lambert function is crystal-clear. $\endgroup$ – J. M. isn't a mathematician Sep 5 '10 at 23:01
  • $\begingroup$ Heh, should've done that to begin with. Thank you Kaestur! $\endgroup$ – J. M. isn't a mathematician Sep 5 '10 at 23:30

I don't think the radius has to involve the variance. You could just use the radius to scale the x-axis.

So you could sample the distribution from -1 to 1, always. If the radius is 4, would sample 9 regions. For 10 you sample 21 times between -1 and 1. The variance can stay the same.

You might want to try this question here too https://gamedev.stackexchange.com/.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.