From 5bd6c411b1110e213255a33c76f40bff574508d7 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 18 Jan 2017 21:30:46 -0600 Subject: [PATCH] added contrast stretching to stim::image --- stim/image/image.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+), 0 deletions(-) diff --git a/stim/image/image.h b/stim/image/image.h index eda65d7..38da7ec 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -384,6 +384,21 @@ public: } + /// Stretch the contrast of the image such that the minimum and maximum intensity match the given values + image stretch(T low, T high) { + T maxval = maxv(); + T minval = minv(); + + image result = *this; //create a new image for output + size_t N = size(); //get the number of values in the image + double range = maxval - minval; //calculate the current range of the image + double desired_range = high - low; //calculate the desired range of the image + for (size_t n = 0; n < N; n++) { //for each element in the image + result.data()[n] = desired_range * (img[n] - minval) / range; + } + return result; + } + /// Copy the given data to the specified channel /// @param c is the channel number that the data will be copied to -- libgit2 0.21.4