Commit 740f8cd2eaa4f6c9204ecb35047c0b65105d1440
1 parent
f4c5d71b
added apply_mask
Showing
4 changed files
with
123 additions
and
0 deletions
Show diff stats
envi/bil.h
@@ -685,6 +685,36 @@ public: | @@ -685,6 +685,36 @@ public: | ||
685 | return true; | 685 | return true; |
686 | } | 686 | } |
687 | 687 | ||
688 | + //apply mask | ||
689 | + bool apply_mask(std::string outfile, unsigned char* p){ | ||
690 | + | ||
691 | + std::ofstream target(outfile.c_str(), std::ios::binary); | ||
692 | + | ||
693 | + unsigned XZ = R[0] * R[2]; //calculate number of a band | ||
694 | + unsigned L = XZ * sizeof(T); | ||
695 | + | ||
696 | + T * temp = (T*)malloc(L); | ||
697 | + | ||
698 | + for (unsigned i = 0; i < R[1]; i++) | ||
699 | + { | ||
700 | + getY(temp, i); | ||
701 | + for ( unsigned j = 0; j < R[2]; j++) | ||
702 | + { | ||
703 | + for (unsigned k = 0; k < R[0]; k++) | ||
704 | + { | ||
705 | + if(p[i * R[0] + k] == 0) | ||
706 | + temp[j * R[0] + k] = 0; | ||
707 | + else | ||
708 | + continue; | ||
709 | + } | ||
710 | + } | ||
711 | + target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file | ||
712 | + } | ||
713 | + target.close(); | ||
714 | + free(temp); | ||
715 | + return true; | ||
716 | + } | ||
717 | + | ||
688 | //close the file | 718 | //close the file |
689 | bool close(){ | 719 | bool close(){ |
690 | file.close(); | 720 | file.close(); |
envi/bip.h
@@ -777,6 +777,36 @@ public: | @@ -777,6 +777,36 @@ public: | ||
777 | 777 | ||
778 | } | 778 | } |
779 | 779 | ||
780 | + //apply mask | ||
781 | + bool apply_mask(std::string outfile, unsigned char* p){ | ||
782 | + | ||
783 | + std::ofstream target(outfile.c_str(), std::ios::binary); | ||
784 | + | ||
785 | + unsigned ZX = R[2] * R[0]; //calculate number of a band | ||
786 | + unsigned L = ZX * sizeof(T); | ||
787 | + | ||
788 | + T * temp = (T*)malloc(L); | ||
789 | + | ||
790 | + for (unsigned i = 0; i < R[1]; i++) | ||
791 | + { | ||
792 | + getY(temp, i); | ||
793 | + for ( unsigned j = 0; j < R[0]; j++) | ||
794 | + { | ||
795 | + for (unsigned k = 0; k < R[2]; k++) | ||
796 | + { | ||
797 | + if(p[i * R[0] + k] == 0) | ||
798 | + temp[j * R[2] + k] = 0; | ||
799 | + else | ||
800 | + continue; | ||
801 | + } | ||
802 | + } | ||
803 | + target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file | ||
804 | + } | ||
805 | + target.close(); | ||
806 | + free(temp); | ||
807 | + return true; | ||
808 | + } | ||
809 | + | ||
780 | //close the file | 810 | //close the file |
781 | bool close(){ | 811 | bool close(){ |
782 | file.close(); | 812 | file.close(); |
envi/bsq.h
@@ -612,6 +612,37 @@ public: | @@ -612,6 +612,37 @@ public: | ||
612 | return true; | 612 | return true; |
613 | 613 | ||
614 | } | 614 | } |
615 | + | ||
616 | + //apply mask | ||
617 | + bool apply_mask(std::string outfile, unsigned char* p){ | ||
618 | + | ||
619 | + std::ofstream target(outfile.c_str(), std::ios::binary); | ||
620 | + | ||
621 | + unsigned XY = R[0] * R[1]; //calculate number of a band | ||
622 | + unsigned L = XY * sizeof(T); | ||
623 | + | ||
624 | + T * temp = (T*)malloc(L); | ||
625 | + | ||
626 | + for (unsigned i = 0; i < R[2]; i++) | ||
627 | + { | ||
628 | + band_index(temp, i); | ||
629 | + for ( unsigned j = 0; j < XY; j++) | ||
630 | + { | ||
631 | + if(p[j] == 0){ | ||
632 | + temp[j] = 0; | ||
633 | + } | ||
634 | + else{ | ||
635 | + continue; | ||
636 | + } | ||
637 | + } | ||
638 | + target.write(reinterpret_cast<const char*>(temp), L); //write a band data into target file | ||
639 | + } | ||
640 | + target.close(); | ||
641 | + free(temp); | ||
642 | + return true; | ||
643 | + } | ||
644 | + | ||
645 | + | ||
615 | //close the file | 646 | //close the file |
616 | bool close(){ | 647 | bool close(){ |
617 | file.close(); | 648 | file.close(); |
envi/envi.h
@@ -302,6 +302,38 @@ public: | @@ -302,6 +302,38 @@ public: | ||
302 | else | 302 | else |
303 | std::cout<<"ERROR: unidentified data type"<<std::endl; | 303 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
304 | } | 304 | } |
305 | + } | ||
306 | + | ||
307 | + //apply mask | ||
308 | + bool apply_mask(std::string outfile, unsigned char* p) | ||
309 | + { | ||
310 | + | ||
311 | + if(header.interleave == envi_header::BSQ){ //if the infile is bsq file | ||
312 | + if(header.data_type ==envi_header::float32) | ||
313 | + return ((bsq<float>*)file)->apply_mask(outfile, p); | ||
314 | + else if(header.data_type == envi_header::float64) | ||
315 | + return ((bsq<double>*)file)->apply_mask(outfile, p); | ||
316 | + else | ||
317 | + std::cout<<"ERROR: unidentified data type"<<std::endl; | ||
318 | + } | ||
319 | + | ||
320 | + else if(header.interleave == envi_header::BIL){ //if the infile is bil file | ||
321 | + if(header.data_type ==envi_header::float32) | ||
322 | + return ((bil<float>*)file)->apply_mask(outfile, p); | ||
323 | + else if(header.data_type == envi_header::float64) | ||
324 | + return ((bil<double>*)file)->apply_mask(outfile, p); | ||
325 | + else | ||
326 | + std::cout<<"ERROR: unidentified data type"<<std::endl; | ||
327 | + } | ||
328 | + | ||
329 | + else if(header.interleave == envi_header::BIP){ //if the infile is bip file | ||
330 | + if(header.data_type ==envi_header::float32) | ||
331 | + return ((bip<float>*)file)->apply_mask(outfile, p); | ||
332 | + else if(header.data_type == envi_header::float64) | ||
333 | + return ((bip<double>*)file)->apply_mask(outfile, p); | ||
334 | + else | ||
335 | + std::cout<<"ERROR: unidentified data type"<<std::endl; | ||
336 | + } | ||
305 | 337 | ||
306 | else{ | 338 | else{ |
307 | std::cout<<"ERROR: unidentified file type"<<std::endl; | 339 | std::cout<<"ERROR: unidentified file type"<<std::endl; |