-
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
Changes from 5 commits
1938e66
fe60d73
db7154a
10ba229
e0d411d
d30e122
d58478c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,18 +23,20 @@ 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 | ||
require(lower < upper) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Here it should be |
||
}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 commentThe 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. |
||
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.) */ | ||
|
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)