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

Fix for normalizeDoubleImage #92

Merged
merged 7 commits into from
Apr 4, 2018
Merged

Conversation

fox918
Copy link
Contributor

@fox918 fox918 commented Mar 9, 2018

added require for arguments
added mean if image min == image max

please do not look at the few other commits inbetween...

Copy link
Member

@Andreas-Forster Andreas-Forster left a 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]
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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.
@Andreas-Forster Andreas-Forster merged commit efadeba into unibas-gravis:master Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants