-
Notifications
You must be signed in to change notification settings - Fork 27
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
Fix for normalizeDoubleImage #92
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR which really corrects something I consider being a bug. I agree with merging if you address the minor issues I commented.
val min = image.values.min | ||
val max = image.values.max | ||
if(min == max){ //if we would divide with 0 | ||
image.map(_ => (upper-lower)/2) //return mean of [lower,upper] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it should be (lower+upper)/2
or lower+(upper-lower)/2
. I would calculate the constant one above so that it is even better visible that the map does not depend on the position.
if (lower < 0.0 || upper > 1.0) | ||
image | ||
else | ||
require(lower < upper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The require
can be removed as it does not change the correctness. Hence we could invert an image by: normalizeDoubleImageToRange(image,max,min)
if(min == max){ //if we would divide with 0 | ||
image.map(_ => (upper-lower)/2) //return mean of [lower,upper] | ||
}else { | ||
def normalizer(x: Double) = lower + (x - min) / (max - min) * (upper - lower) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you precompute the normalization outside of the function? It might be more efficient except it is optimized by the compiler or the JVM and not much less readable I think.
Fixes according to comments from PR in unibas-gravis/scalismo-faces.
Sorry I introduced a bug which should now be fixed.
added require for arguments
added mean if image min == image max
please do not look at the few other commits inbetween...