diff --git a/stim/envi/bil.h b/stim/envi/bil.h index 7bc1eaf..08af5f2 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -828,16 +828,19 @@ public: /// @param mask_band is the band used to specify the mask /// @param threshold is the threshold used to determine if the mask value is true or false /// @param p is a pointer to a pre-allocated array at least X * Y in size - bool build_mask(unsigned char* mask, double mask_band, double threshold, bool PROGRESS = false){ + bool build_mask(unsigned char* out_mask, double mask_band, double lower, double upper, unsigned char* mask = NULL, bool PROGRESS = false){ T* temp = (T*)malloc(X() * Y() * sizeof(T)); //allocate memory for the certain band band(temp, mask_band, PROGRESS); for (unsigned long long i = 0; i < X() * Y(); i++) { - if (temp[i] < threshold) - mask[i] = 0; - else - mask[i] = 255; + if(mask == NULL || mask[i] != 0){ + if(temp[i] > lower && temp[i] < upper){ + out_mask[i] = 255; + } + else + out_mask[i] = 0; + } } free(temp); diff --git a/stim/envi/bip.h b/stim/envi/bip.h index 19bc1bd..31d706f 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -762,16 +762,19 @@ public: /// @param mask_band is the band used to specify the mask /// @param threshold is the threshold used to determine if the mask value is true or false /// @param p is a pointer to a pre-allocated array at least X * Y in size - bool build_mask(unsigned char* mask, double mask_band, double threshold, bool PROGRESS = false){ + bool build_mask(unsigned char* out_mask, double mask_band, double lower, double upper, unsigned char* mask = NULL, bool PROGRESS = false){ T* temp = (T*)malloc(X() * Y() * sizeof(T)); //allocate memory for the certain band band(temp, mask_band, PROGRESS); for (unsigned long long i = 0; i < X() * Y();i++) { - if (temp[i] < threshold) - mask[i] = 0; - else - mask[i] = 255; + if(mask == NULL || mask[i] != 0){ + if(temp[i] > lower && temp[i] < upper){ + out_mask[i] = 255; + } + else + out_mask[i] = 0; + } } free(temp); diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index 6d894b0..670c1dd 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -914,16 +914,20 @@ public: /// @param mask_band is the band used to specify the mask /// @param threshold is the threshold used to determine if the mask value is true or false /// @param p is a pointer to a pre-allocated array at least X * Y in size - bool build_mask(unsigned char* mask, double mask_band, double threshold, bool PROGRESS = false){ + bool build_mask(unsigned char* out_mask, double mask_band, double lower, double upper, unsigned char* mask = NULL, bool PROGRESS = false){ + memset(out_mask, 0, X() * Y()); //initialize the mask to zero T* temp = (T*)malloc(X() * Y() * sizeof(T)); //allocate memory for the certain band band(temp, mask_band); for (unsigned long long i = 0; i < X() * Y(); i++) { - if (temp[i] < threshold) - mask[i] = 0; - else - mask[i] = 255; + if(mask == NULL || mask[i] != 0){ + if(temp[i] > lower && temp[i] < upper){ + out_mask[i] = 255; + } + else + out_mask[i] = 0; + } if(PROGRESS) progress = (double) (i+1) / (X() * Y()) * 100; } diff --git a/stim/envi/envi.h b/stim/envi/envi.h index 5fd0cb1..6687b08 100644 --- a/stim/envi/envi.h +++ b/stim/envi/envi.h @@ -718,31 +718,31 @@ public: /// @param mask_band is the label for the band that will be used to build the mask /// @param threshold is a value selected such that all band values greater than threshold will have a mask value of 'true' /// @param p is memory of size X*Y that will store the resulting mask - bool build_mask(unsigned char* mask, double mask_band, double threshold, bool PROGRESS = false) { + bool build_mask(unsigned char* out_mask, double mask_band, double lower, double upper, unsigned char* mask = NULL, bool PROGRESS = false) { if(header.interleave == envi_header::BSQ){ //if the infile is bsq file if(header.data_type ==envi_header::float32) - return ((bsq*)file)->build_mask(mask, mask_band, threshold, PROGRESS); + return ((bsq*)file)->build_mask(out_mask, mask_band, lower, upper, mask, PROGRESS); else if(header.data_type == envi_header::float64) - return ((bsq*)file)->build_mask(mask, mask_band, threshold, PROGRESS); + return ((bsq*)file)->build_mask(out_mask, mask_band, lower, upper, mask, PROGRESS); else std::cout<<"ERROR: unidentified data type"<*)file)->build_mask(mask, mask_band, threshold, PROGRESS); + return ((bil*)file)->build_mask(out_mask, mask_band, lower, upper, mask, PROGRESS); else if(header.data_type == envi_header::float64) - return ((bil*)file)->build_mask(mask, mask_band, threshold, PROGRESS); + return ((bil*)file)->build_mask(out_mask, mask_band, lower, upper, mask, PROGRESS); else std::cout<<"ERROR: unidentified data type"<*)file)->build_mask(mask, mask_band, threshold, PROGRESS); + return ((bip*)file)->build_mask(out_mask, mask_band, lower, upper, mask, PROGRESS); else if(header.data_type == envi_header::float64) - return ((bip*)file)->build_mask(mask, mask_band, threshold, PROGRESS); + return ((bip*)file)->build_mask(out_mask, mask_band, lower, upper, mask, PROGRESS); else std::cout<<"ERROR: unidentified data type"<*)file)->mask_finite(mask, PROGRESS); + ((bsq*)file)->mask_finite(out_mask, mask, PROGRESS); else if(header.data_type == envi_header::float64) - ((bsq*)file)->mask_finite(mask, PROGRESS); + ((bsq*)file)->mask_finite(out_mask, mask, PROGRESS); else std::cout<<"ERROR: unidentified data type"<*)file)->mask_finite(mask, PROGRESS); + ((bil*)file)->mask_finite(out_mask, mask, PROGRESS); else if(header.data_type == envi_header::float64) - ((bil*)file)->mask_finite(mask, PROGRESS); + ((bil*)file)->mask_finite(out_mask, mask, PROGRESS); else std::cout<<"ERROR: unidentified data type"<*)file)->mask_finite(mask, PROGRESS); + ((bip*)file)->mask_finite(out_mask, mask, PROGRESS); else if(header.data_type == envi_header::float64) - ((bip*)file)->mask_finite(mask, PROGRESS); + ((bip*)file)->mask_finite(out_mask, mask, PROGRESS); else std::cout<<"ERROR: unidentified data type"<