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
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/main/scala/scalismo/faces/image/PixelImageNormalization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ object PixelImageNormalization {

/** Normalizes the image such that its values are on the interval [lower, upper]. */
def normalizeDoubleImageToRange(image: PixelImage[Double], lower: Double, upper: Double): PixelImage[Double] = {
def normalizer(x: Double) = (x - lower) / (upper - lower)
if (lower < 0.0 || upper > 1.0)
image
else
val min = image.values.min
val max = image.values.max
if(min == max){ //if we would divide with 0
val avg = (upper+lower)/2
image.map(avg) //return mean of [lower,upper]
}else {
val Z = 1.0 / (max - min) * (upper - lower)
def normalizer(x: Double) = lower + (x - min) * Z
image.map(normalizer)
}
}

/** Expands value range to the interval [0,1]. */
def normalizeDoubleImage(image: PixelImage[Double]): PixelImage[Double] = {
val min = image.values.min
val max = image.values.max
normalizeDoubleImageToRange(image, min, max)
normalizeDoubleImageToRange(image, 0.0, 1.0)
}

/** Normalize the image to range ([0,1], [0,1], [0,1]). (Each channel is normalized seperately.) */
Expand Down