diff --git a/stim/image/image.h b/stim/image/image.h index a711abd..a479eb5 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -402,15 +402,13 @@ public: /// Set all elements in the image to a given scalar value /// @param v is the value used to set all values in the image - image operator=(T v){ - + void set_all(T v) { //set all elements of the image to a given value v size_t N = size(); - - for(size_t n = 0; n < N; n++) - img[n] = v; - + for (size_t n = 0; n < N; n++) img[n] = v; + } + image operator=(T v){ + set_all(v); return *this; - } /// invert the image, given a specified maximum value (ex. maxval = 255, I' = 255 - I) @@ -426,8 +424,12 @@ public: image stretch(T low, T high) { T maxval = maxv(); T minval = minv(); - image result = *this; //create a new image for output + if (maxval == minval) { //if the minimum and maximum values are the same, return an image composed of low + result = low; + return result; + } + size_t N = size(); //get the number of values in the image T range = maxval - minval; //calculate the current range of the image T desired_range = high - low; //calculate the desired range of the image -- libgit2 0.21.4