Commit 4a6f666c0f5db7de6bb74221eb8306f699658ccc

Authored by heziqi
1 parent 646a89c5

Added mask method

Showing 4 changed files with 85 additions and 4 deletions   Show diff stats
@@ -387,6 +387,22 @@ public: @@ -387,6 +387,22 @@ public:
387 return true; 387 return true;
388 } 388 }
389 389
  390 + //create mask file
  391 + bool mask(unsigned char* p, double mask_band, double threshold){
  392 +
  393 + T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
  394 + band(temp, mask_band);
  395 +
  396 + for (unsigned int i = 0; i < R[0] * R[1]; i++) {
  397 + if (temp[i] < threshold)
  398 + p[i] = 0;
  399 + else
  400 + p[i] = 255;
  401 + }
  402 +
  403 + return true;
  404 + }
  405 +
390 //close the file 406 //close the file
391 bool close(){ 407 bool close(){
392 file.close(); 408 file.close();
@@ -477,6 +477,23 @@ public: @@ -477,6 +477,23 @@ public:
477 return true; 477 return true;
478 } 478 }
479 479
  480 + //create mask file
  481 + bool mask(unsigned char* p, double mask_band, double threshold){
  482 +
  483 + T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
  484 + band(temp, mask_band);
  485 +
  486 + for (unsigned int i = 0; i < R[0] * R[1];i++) {
  487 + if (temp[i] < threshold)
  488 + p[i] = 0;
  489 + else
  490 + p[i] = 255;
  491 + }
  492 +
  493 + return true;
  494 +
  495 + }
  496 +
480 //close the file 497 //close the file
481 bool close(){ 498 bool close(){
482 file.close(); 499 file.close();
@@ -310,6 +310,22 @@ public: @@ -310,6 +310,22 @@ public:
310 return true; 310 return true;
311 } 311 }
312 312
  313 + //create mask file
  314 + bool mask(unsigned char* p, double mask_band, double threshold){
  315 +
  316 + T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band
  317 + band(temp, mask_band);
  318 +
  319 + for (unsigned int i = 0; i < R[0] * R[1]; i++) {
  320 + if (temp[i] < threshold)
  321 + p[i] = 0;
  322 + else
  323 + p[i] = 255;
  324 + }
  325 +
  326 + return true;
  327 +
  328 + }
313 //close the file 329 //close the file
314 bool close(){ 330 bool close(){
315 file.close(); 331 file.close();
@@ -9,14 +9,14 @@ @@ -9,14 +9,14 @@
9 namespace rts{ 9 namespace rts{
10 10
11 //container class for an ENVI binary file reader 11 //container class for an ENVI binary file reader
12 -class envi{  
13 -  
14 - envi_header header; 12 +class envi{
15 13
16 void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type) 14 void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type)
17 15
18 public: 16 public:
19 17
  18 + envi_header header;
  19 +
20 bool allocate(){ 20 bool allocate(){
21 21
22 file = NULL; //set file to a NULL pointer 22 file = NULL; //set file to a NULL pointer
@@ -274,8 +274,40 @@ public: @@ -274,8 +274,40 @@ public:
274 } 274 }
275 275
276 //get the mask 276 //get the mask
277 - bool mask(unsigned char* mask, mask_band, threshold) { 277 + bool mask(unsigned char* p, double mask_band, double threshold) {
  278 +
  279 + if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
  280 + if(header.data_type ==envi_header::float32)
  281 + return ((bsq<float>*)file)->mask(p, mask_band, threshold);
  282 + else if(header.data_type == envi_header::float64)
  283 + return ((bsq<double>*)file)->mask(p, mask_band, threshold);
  284 + else
  285 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  286 + }
  287 +
  288 + else if(header.interleave == envi_header::BIL){ //if the infile is bil file
  289 + if(header.data_type ==envi_header::float32)
  290 + return ((bil<float>*)file)->mask(p, mask_band, threshold);
  291 + else if(header.data_type == envi_header::float64)
  292 + return ((bil<double>*)file)->mask(p, mask_band, threshold);
  293 + else
  294 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  295 + }
278 296
  297 + else if(header.interleave == envi_header::BIP){ //if the infile is bip file
  298 + if(header.data_type ==envi_header::float32)
  299 + return ((bip<float>*)file)->mask(p, mask_band, threshold);
  300 + else if(header.data_type == envi_header::float64)
  301 + return ((bip<double>*)file)->mask(p, mask_band, threshold);
  302 + else
  303 + std::cout<<"ERROR: unidentified data type"<<std::endl;
  304 + }
  305 +
  306 + else{
  307 + std::cout<<"ERROR: unidentified file type"<<std::endl;
  308 + exit(1);
  309 + }
  310 + return false;
279 } 311 }
280 312
281 bool close(){ 313 bool close(){