Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure output of Normalize is bounded between zero and one #1400

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

bruno-f-cruz
Copy link
Contributor

Fixes #1399 .

The current version of Normalize implements ConvertScale with shift in "raw", unscaled, units.

https://github.com/bonsai-rx/bonsai/blob/404b092b501fbd9a0db5ccce76bf695623e6ba7c/Bonsai.Vision/Normalize.cs#LL34C17-L34C32

                var range = max - min;
                var scale = range > 0 ? 1.0 / range : 0;
                var shift = range > 0 ? -min : 0;
                CV.ConvertScale(input, output, scale, shift);

However, the native function from opencv seems to follow algebraic order of operations (i.e. Multiplication -> Addition), resulting in applying the scaling first and the shift second.

image

It seems the easiest way to correct this would be to normalize the shift by the range:

var shift = range > 0 ? -min*scale : 0;

@glopesdev glopesdev added the fix Pull request that fixes an issue label Jul 5, 2023
@glopesdev glopesdev added this to the 2.8 milestone Jul 5, 2023
@glopesdev glopesdev changed the title Ensure Normalize output is bounded to [0,1] Ensure output of Normalize is bounded between zero and one Jul 5, 2023
@glopesdev glopesdev self-requested a review July 5, 2023 10:15
@glopesdev glopesdev merged commit 79454c0 into bonsai-rx:main Jul 5, 2023
@bruno-f-cruz bruno-f-cruz deleted the #1399 branch July 5, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Pull request that fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Normalize fails to produce values between 0 and 1
2 participants