From 4a6f666c0f5db7de6bb74221eb8306f699658ccc Mon Sep 17 00:00:00 2001 From: heziqi Date: Sat, 11 Oct 2014 05:46:02 +0800 Subject: [PATCH] Added mask method --- envi/bil.h | 16 ++++++++++++++++ envi/bip.h | 17 +++++++++++++++++ envi/bsq.h | 16 ++++++++++++++++ envi/envi.h | 40 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/envi/bil.h b/envi/bil.h index 6b0ef9b..0333ad6 100644 --- a/envi/bil.h +++ b/envi/bil.h @@ -387,6 +387,22 @@ public: return true; } + //create mask file + bool mask(unsigned char* p, double mask_band, double threshold){ + + T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band + band(temp, mask_band); + + for (unsigned int i = 0; i < R[0] * R[1]; i++) { + if (temp[i] < threshold) + p[i] = 0; + else + p[i] = 255; + } + + return true; + } + //close the file bool close(){ file.close(); diff --git a/envi/bip.h b/envi/bip.h index 336a1ca..61cd958 100644 --- a/envi/bip.h +++ b/envi/bip.h @@ -477,6 +477,23 @@ public: return true; } + //create mask file + bool mask(unsigned char* p, double mask_band, double threshold){ + + T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band + band(temp, mask_band); + + for (unsigned int i = 0; i < R[0] * R[1];i++) { + if (temp[i] < threshold) + p[i] = 0; + else + p[i] = 255; + } + + return true; + + } + //close the file bool close(){ file.close(); diff --git a/envi/bsq.h b/envi/bsq.h index 4548c01..a9746d2 100644 --- a/envi/bsq.h +++ b/envi/bsq.h @@ -310,6 +310,22 @@ public: return true; } + //create mask file + bool mask(unsigned char* p, double mask_band, double threshold){ + + T* temp = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate memory for the certain band + band(temp, mask_band); + + for (unsigned int i = 0; i < R[0] * R[1]; i++) { + if (temp[i] < threshold) + p[i] = 0; + else + p[i] = 255; + } + + return true; + + } //close the file bool close(){ file.close(); diff --git a/envi/envi.h b/envi/envi.h index 4efe52e..28f2ac9 100644 --- a/envi/envi.h +++ b/envi/envi.h @@ -9,14 +9,14 @@ namespace rts{ //container class for an ENVI binary file reader -class envi{ - - envi_header header; +class envi{ void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type) public: + envi_header header; + bool allocate(){ file = NULL; //set file to a NULL pointer @@ -274,8 +274,40 @@ public: } //get the mask - bool mask(unsigned char* mask, mask_band, threshold) { + bool mask(unsigned char* p, double mask_band, double threshold) { + + if(header.interleave == envi_header::BSQ){ //if the infile is bsq file + if(header.data_type ==envi_header::float32) + return ((bsq*)file)->mask(p, mask_band, threshold); + else if(header.data_type == envi_header::float64) + return ((bsq*)file)->mask(p, mask_band, threshold); + else + std::cout<<"ERROR: unidentified data type"<*)file)->mask(p, mask_band, threshold); + else if(header.data_type == envi_header::float64) + return ((bil*)file)->mask(p, mask_band, threshold); + else + std::cout<<"ERROR: unidentified data type"<*)file)->mask(p, mask_band, threshold); + else if(header.data_type == envi_header::float64) + return ((bip*)file)->mask(p, mask_band, threshold); + else + std::cout<<"ERROR: unidentified data type"<