Clear Filters
Clear Filters

what value should i give for hsize and sigma in fspecial (gaussian) function???

4 views (last 30 days)
h=fspecial('gaussian',?,?)

Answers (2)

Wayne King
Wayne King on 29 Mar 2014
That really depends on your filtering application. Obviously the bigger hsize, the larger the neighborhood you are filtering over, and the larger sigma, the larger the spread of the filter in that neighborhood.
How much are you trying to smooth out your data?

DGM
DGM on 8 Mar 2022
Edited: DGM on 8 Mar 2022
Unless you have other needs, just pick a sigma value and then calculate hsize like so:
sigma = 20; % this depends on your needs
kw = 2; % typical might be 2-3
fk = fspecial('gaussian',2*ceil(kw*sigma)+1,sigma);
Changing the hsize parameter only changes the support area. For example, these are filters for sigma = 20 and kw = 1-4
Note that the gaussians are all the same. Hsize just specifies where it gets truncated. A smaller filter is faster to apply, but the harder edges sacrifice some of the benefits of using a gaussian. Picking a size is just a matter of compromise between speed and quality.
I should note that fspecial() does support asymmetric hsize. That said, making hsize asymmetric doesn't change the symmetry of the underlying gaussian. With that in mind and considering the fact that fspecial() doesn't accept vector sigma, I don't see much purpose for using asymmetric hsize.

Community Treasure Hunt

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

Start Hunting!