diff --git a/envi/bil.h b/envi/bil.h index 344e4b9..ff36234 100644 --- a/envi/bil.h +++ b/envi/bil.h @@ -685,6 +685,36 @@ public: return true; } + //apply mask + bool apply_mask(std::string outfile, unsigned char* p){ + + std::ofstream target(outfile.c_str(), std::ios::binary); + + unsigned XZ = R[0] * R[2]; //calculate number of a band + unsigned L = XZ * sizeof(T); + + T * temp = (T*)malloc(L); + + for (unsigned i = 0; i < R[1]; i++) + { + getY(temp, i); + for ( unsigned j = 0; j < R[2]; j++) + { + for (unsigned k = 0; k < R[0]; k++) + { + if(p[i * R[0] + k] == 0) + temp[j * R[0] + k] = 0; + else + continue; + } + } + target.write(reinterpret_cast(temp), L); //write a band data into target file + } + target.close(); + free(temp); + return true; + } + //close the file bool close(){ file.close(); diff --git a/envi/bip.h b/envi/bip.h index bd75907..98ec0c2 100644 --- a/envi/bip.h +++ b/envi/bip.h @@ -777,6 +777,36 @@ public: } + //apply mask + bool apply_mask(std::string outfile, unsigned char* p){ + + std::ofstream target(outfile.c_str(), std::ios::binary); + + unsigned ZX = R[2] * R[0]; //calculate number of a band + unsigned L = ZX * sizeof(T); + + T * temp = (T*)malloc(L); + + for (unsigned i = 0; i < R[1]; i++) + { + getY(temp, i); + for ( unsigned j = 0; j < R[0]; j++) + { + for (unsigned k = 0; k < R[2]; k++) + { + if(p[i * R[0] + k] == 0) + temp[j * R[2] + k] = 0; + else + continue; + } + } + target.write(reinterpret_cast(temp), L); //write a band data into target file + } + target.close(); + free(temp); + return true; + } + //close the file bool close(){ file.close(); diff --git a/envi/bsq.h b/envi/bsq.h index 9a97291..a2d06e7 100644 --- a/envi/bsq.h +++ b/envi/bsq.h @@ -612,6 +612,37 @@ public: return true; } + + //apply mask + bool apply_mask(std::string outfile, unsigned char* p){ + + std::ofstream target(outfile.c_str(), std::ios::binary); + + unsigned XY = R[0] * R[1]; //calculate number of a band + unsigned L = XY * sizeof(T); + + T * temp = (T*)malloc(L); + + for (unsigned i = 0; i < R[2]; i++) + { + band_index(temp, i); + for ( unsigned j = 0; j < XY; j++) + { + if(p[j] == 0){ + temp[j] = 0; + } + else{ + continue; + } + } + target.write(reinterpret_cast(temp), L); //write a band data into target file + } + target.close(); + free(temp); + return true; + } + + //close the file bool close(){ file.close(); diff --git a/envi/envi.h b/envi/envi.h index 78aeac0..6e9459d 100644 --- a/envi/envi.h +++ b/envi/envi.h @@ -302,6 +302,38 @@ public: else std::cout<<"ERROR: unidentified data type"<*)file)->apply_mask(outfile, p); + else if(header.data_type == envi_header::float64) + return ((bsq*)file)->apply_mask(outfile, p); + else + std::cout<<"ERROR: unidentified data type"<*)file)->apply_mask(outfile, p); + else if(header.data_type == envi_header::float64) + return ((bil*)file)->apply_mask(outfile, p); + else + std::cout<<"ERROR: unidentified data type"<*)file)->apply_mask(outfile, p); + else if(header.data_type == envi_header::float64) + return ((bip*)file)->apply_mask(outfile, p); + else + std::cout<<"ERROR: unidentified data type"<