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

2 次查看(过去 30 天)
h=fspecial('gaussian',?,?)

回答(2 个)

Wayne King
Wayne King 2014-3-29
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 2022-3-8
编辑:DGM 2022-3-8
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!

Translated by