What is the correct number of pixels for a Gaussian with a given standard deviation?

57 views (last 30 days)
Assume, by some method, I have evaluated that my point spread function is a Gaussian with \sigma = 3 (standard deviation)
How many pixels should I assign to my Gaussian filter in Matlab?
I understand that we can truncate a Gaussian at 3*\sigma and also we can create a filter of size 5*\sigma (to be conservative). But why we can't go larger?
Assume I have an image of size 1024*1024. For the described case, I choose a filter of size 15:
G = fspecial('gaussian', [15,15], 3);
It makes sense, but it is different from:
G = fspecial('gaussian', [31,31], 3);
The latter is a sharper Gaussian rather than a higher resolution (finer discretized) one.
What is the correct size for a Gaussian of standard deviation \sigma?

Accepted Answer

Matt Cohen
Matt Cohen on 29 Jul 2015
Hi Elham,
I understand that you would like to know about choosing the size (number of pixels) of a Gaussian filter with a standard deviation value of 3.
The rule of thumb for Gaussian filter design is to choose the filter size to be about 3 times the standard deviation (sigma value) in each direction, for a total filter size of approximately 6*sigma rounded to an odd integer value. This goes along with what you mentioned about truncating the Gaussian at 3*sigma.
In theory, you could go larger than 3*sigma, and even larger than 5*sigma, but there is not much of a benefit from doing this. The tails of a Gaussian function have amplitude that is effectively zero beyond three standard deviations from the mean, so keeping these filter coefficients does little to effect the result of filtering. It is also desired to ensure that a filter's edges go to zero on all sides. Additionally, truncating at 3*sigma prevents the Gaussian filter from becoming too large, which makes the filtering process more computationally efficient.
Based on the rule of thumb, you would want the Gaussian filter with a standard deviation of 3 to have a size of approximately 19x19. This is because you want 3*sigma pixels in each direction, and 2*3*sigma = 2*3*3 = 18, which becomes 19 after rounding up to the nearest odd integer. Using only 15 pixels does not capture the full bell shape of the Gaussian and does not force the filter's edges to zero, which can produce undesirable effects. Using 31 pixels, on the other hand, extends well beyond the 3*sigma point, so the edges do go to zero; however, these outer coefficients provide little benefit since they have values of zero.
As mentioned in the documentation for "fspecial" (MATLAB R2015a only), using "fspecial" is not recommended for 2-D Gaussian filtering of images. Instead, the "imgaussfilt" function should be used. This function takes in an image matrix, and optionally the sigma value and size of the Gaussian filter, and returns the filtered image.
I hope this helps.
Matt
  2 Comments
elham sa
elham sa on 29 Jul 2015
You are right Matt. It doesn't matter how large we go as long as we look at the spatial or frequency content at correct resolution.
For example:
G = fspecial('gaussian' , [19,19],3);
MTF = psf2otf(G,[400,400]); %OTF is real in this case
figure; mesh(fftshift(MTF));
is not different from:
G = fspecial('gaussian' , [61,61],3);
MTF = psf2otf(G,[400,400]);
figure; mesh(fftshift(MTF));
But if we look at MTF not at a fixed resolution (i.e. 400*400 here) the MTF "looks" different, which is not the correct way of doing this.
Thank you very much for your answer!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!