Difference between manually-created gaussian filter and fspecial
6 次查看(过去 30 天)
显示 更早的评论
I am wondering why there is difference between these two, and how could the max vaule in fspecial (0.4026) is larger than manually-created gaussian (0.3989) when x = 0?
manually-created gaussian filter code:
x = [-2 -1 0 1 2];
gauss_filter = 1/(sqrt(2*pi)*sigma)*exp(-x.^2/(2*sigma^2))
gauss_filter =
0.0540 0.2420 0.3989 0.2420 0.0540
while the fspecial create gaussian filter:
gauss_filter = 1/(sqrt(2*pi)*sigma)*exp(-x.^2/(2*sigma^2))'
gauss_filter =
0.0545 0.2442 0.4026 0.2442 0.0545
0 个评论
回答(1 个)
DGM
2024-10-24,23:57
编辑:DGM
2024-10-24,23:58
I believe the original question was pasted incorrectly, since both examples appear to be identical (except a transpose). Neither shows the use of fspecial().
However, the difference between the two results is simple. For the filters to not alter the image mean, their sum must be 1.
sigma = 1;
x = [-2 -1 0 1 2];
fk1 = 1/(sqrt(2*pi)*sigma)*exp(-x.^2/(2*sigma^2)) % as calculated
sum(fk1) % not sum-normalized
fk1 = fk1/sum(fk1) % normalize it
sum(fk1) % sum-normalized
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!