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