Difference between manually-created gaussian filter and fspecial
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
DGM
on 24 Oct 2024
Edited: DGM
on 24 Oct 2024
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!