Commit f4c5d71b85f75cc73ac00ad506ec997794f75e78

Authored by David Mayerich
1 parent ee4dea28

started working with masks

@@ -669,7 +669,7 @@ public: @@ -669,7 +669,7 @@ public:
669 } 669 }
670 670
671 //create mask file 671 //create mask file
672 - bool mask(unsigned char* p, double mask_band, double threshold){ 672 + bool build_mask(double mask_band, double threshold, unsigned char* p){
673 673
674 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band 674 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
675 band(temp, mask_band); 675 band(temp, mask_band);
@@ -20,6 +20,7 @@ protected: @@ -20,6 +20,7 @@ protected:
20 20
21 unsigned int R[D]; //resolution 21 unsigned int R[D]; //resolution
22 unsigned int header; //header size (in bytes) 22 unsigned int header; //header size (in bytes)
  23 + unsigned char* mask; //pointer to a character array: 0 = background, 1 = foreground (or valid data)
23 24
24 25
25 26
@@ -28,7 +29,7 @@ protected: @@ -28,7 +29,7 @@ protected:
28 void init(){ 29 void init(){
29 memset(R, 0, sizeof(unsigned int) * D); //initialize the resolution to zero 30 memset(R, 0, sizeof(unsigned int) * D); //initialize the resolution to zero
30 header = 0; //initialize the header size to zero 31 header = 0; //initialize the header size to zero
31 - 32 + mask = NULL;
32 } 33 }
33 34
34 //returns the file size 35 //returns the file size
@@ -760,7 +760,7 @@ public: @@ -760,7 +760,7 @@ public:
760 } 760 }
761 761
762 //create mask file 762 //create mask file
763 - bool mask(unsigned char* p, double mask_band, double threshold){ 763 + bool build_mask(double mask_band, double threshold, unsigned char* p){
764 764
765 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band 765 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
766 band(temp, mask_band); 766 band(temp, mask_band);
@@ -596,7 +596,7 @@ public: @@ -596,7 +596,7 @@ public:
596 } 596 }
597 597
598 //create mask file 598 //create mask file
599 - bool mask(unsigned char* p, double mask_band, double threshold){ 599 + bool build_mask(double mask_band, double threshold, unsigned char* p = NULL){
600 600
601 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band 601 T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
602 band(temp, mask_band); 602 band(temp, mask_band);
@@ -273,32 +273,32 @@ public: @@ -273,32 +273,32 @@ public:
273 273
274 } 274 }
275 275
276 - //get the mask  
277 - bool mask(unsigned char* p, double mask_band, double threshold) { 276 + //create a mask based on a band and threshold, save it to p (if p is not NULL)
  277 + bool build_mask(double mask_band, double threshold, unsigned char* p = NULL) {
278 278
279 if(header.interleave == envi_header::BSQ){ //if the infile is bsq file 279 if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
280 if(header.data_type ==envi_header::float32) 280 if(header.data_type ==envi_header::float32)
281 - return ((bsq<float>*)file)->mask(p, mask_band, threshold); 281 + return ((bsq<float>*)file)->build_mask(mask_band, threshold, p);
282 else if(header.data_type == envi_header::float64) 282 else if(header.data_type == envi_header::float64)
283 - return ((bsq<double>*)file)->mask(p, mask_band, threshold); 283 + return ((bsq<double>*)file)->build_mask(mask_band, threshold, p);
284 else 284 else
285 std::cout<<"ERROR: unidentified data type"<<std::endl; 285 std::cout<<"ERROR: unidentified data type"<<std::endl;
286 } 286 }
287 287
288 else if(header.interleave == envi_header::BIL){ //if the infile is bil file 288 else if(header.interleave == envi_header::BIL){ //if the infile is bil file
289 if(header.data_type ==envi_header::float32) 289 if(header.data_type ==envi_header::float32)
290 - return ((bil<float>*)file)->mask(p, mask_band, threshold); 290 + return ((bil<float>*)file)->build_mask(mask_band, threshold, p);
291 else if(header.data_type == envi_header::float64) 291 else if(header.data_type == envi_header::float64)
292 - return ((bil<double>*)file)->mask(p, mask_band, threshold); 292 + return ((bil<double>*)file)->build_mask(mask_band, threshold, p);
293 else 293 else
294 std::cout<<"ERROR: unidentified data type"<<std::endl; 294 std::cout<<"ERROR: unidentified data type"<<std::endl;
295 } 295 }
296 296
297 else if(header.interleave == envi_header::BIP){ //if the infile is bip file 297 else if(header.interleave == envi_header::BIP){ //if the infile is bip file
298 if(header.data_type ==envi_header::float32) 298 if(header.data_type ==envi_header::float32)
299 - return ((bip<float>*)file)->mask(p, mask_band, threshold); 299 + return ((bip<float>*)file)->build_mask(mask_band, threshold, p);
300 else if(header.data_type == envi_header::float64) 300 else if(header.data_type == envi_header::float64)
301 - return ((bip<double>*)file)->mask(p, mask_band, threshold); 301 + return ((bip<double>*)file)->build_mask(mask_band, threshold, p);
302 else 302 else
303 std::cout<<"ERROR: unidentified data type"<<std::endl; 303 std::cout<<"ERROR: unidentified data type"<<std::endl;
304 } 304 }