Guide to Writing more Scientifically

From the sigma of a Gaussian to the size in pixels

One of the most used filters in computer vision is the Gaussian filter. Although there are many places where you can find the formula for it, I'll support your laziness and put the 1D version of it here once more:
$$G(x) =\frac{1}{\sigma\sqrt{2\pi}}e^{\frac{x^2}{2\sigma^2}}$$
Informally, its formula comprises two parameters which are responsible for the width \((\sigma)\) and the location of its tip \((\mu)\). The reason you can't see \(\mu\) anywhere in the formula is because I've assumed \(\mu=0\) which just says that the center of the Gaussian is at the center of the plane we're working. This will simplify the calculations and if you need to have your Gaussian somewhere else other than the center, you shift whatever results you get at the end to the place you actually need them.

Sometimes it becomes necessary to fit a given Gaussian to a window within an image. If you just blindly apply the formula starting at, lets say -20 to +20, depending on the Gaussian you're working with, you're going to end up with a chopped version of your Gaussian or with too much empty space around it.



...so to get the right window size (let's call it \(|w|\)) you have to figure out at what point, the value of \(G(x)\) becomes almost zero. To put it a bit more formally, let us solve \(G(x) = \epsilon\), where \(\epsilon\) will be a value that is close enough to zero.
Solving for \(x\), gives the following:

$$\sigma \sqrt{-2(ln(\epsilon \sigma)+ln(\sqrt{2 \pi}))} = x$$

...again, here \(x\) represents the value at which the Gaussian becomes almost zero. Bare in mind that the smaller \(\epsilon\) gets, the larger the blue area will become since more values closer to zero will be considered as part of the curve (e.g. the graphic on the left considers \(\epsilon\) as \(0.001\)). The particular solution could be any real value and since the Gaussian we're using is centered at \((0,0)\), \(x\) is only giving half the width of the window. Obviously, since we're talking about using this in an image which is represented by whole numbers, instead of the real value, you could truncate it or round it. To put it in a formal notation, \(x = \frac{|w|}{2}\). That's pretty much it! If you want the nice final formula for the whole size of a Gaussian it would look something like this:

$$2\sigma \sqrt{-2(ln(\epsilon \sigma)+ln(\sqrt{2 \pi}))} = |w|$$

I hope you find this useful. Happy plotting!

Comments