boostorg / gil

Boost.GIL - Generic Image Library | Requires C++14 since Boost 1.80
https://boostorg.github.io/gil
Boost Software License 1.0
178 stars 164 forks source link

fix: Normalize Gaussian 2D kernel. #725

Closed cgringmuth closed 1 year ago

cgringmuth commented 1 year ago

Description

Gaussian kernel does not sum up to 1 which leads to darkening of image after convolution.

I also rewrote a little the code. Especially const float value = static_cast<float>(nominator / denominator); which should be of type T in my opinion. Otherwise value is always float, independent of T.

References

When converting the Gaussian’s continuous values into the discrete values needed for a kernel, the sum of the values will be different from 1. This will cause a darkening or brightening of the image. To remedy this, the values can be normalized by dividing each term in the kernel by the sum of all terms in the kernel.

from wiki

Tasklist