bfraboni / FastGaussianBlur

Fast Gaussian Blur algorithm
97 stars 18 forks source link

output is a slighty darker when using uchar arrays due to non rounded multiply #4

Closed michelerenzullo closed 2 years ago

michelerenzullo commented 2 years ago

when you multiply the output with float "iarr" and "T" is uchar you should add +0.5f to round it, otherwise the output will be slighty darker, I suggest to add a constexpr to check if T is uchar and so round it, if you do that the output is as expected to be.

https://github.com/bfraboni/FastGaussianBlur/blob/fabc47f62a53a201e685a78e15320aba6e341cfd/fast_gaussian_blur_template.h#L99

GOOD - opencv blur as reference: opencv_blur GOOD - Uchar rounded: FGB_uchar_rounded BAD - Uchar not rounded FGB_uchar

bfraboni commented 2 years ago

Thank you for noticing this. I've run into integer rounding issues before, and had fixed the problem in the code at one point, but it was lost in subsequent changes. The latest commit solves the problem for the two exposed border policies and for any integral type:

https://github.com/bfraboni/FastGaussianBlur/blob/05508f89bd9ad1ed75ade49fb71e5cae75b53f94/fast_gaussian_blur_template.h#L99

https://github.com/bfraboni/FastGaussianBlur/blob/05508f89bd9ad1ed75ade49fb71e5cae75b53f94/fast_gaussian_blur_template.h#L146

Let me know if it fits your needs before I close the issue.

michelerenzullo commented 2 years ago

That's should be perfect, what I thought, dealing with uchar or uint16_t or any integral... I will try in a bit thanks