diff --git a/stim/envi/bil.h b/stim/envi/bil.h index a3fb1ba..0807f30 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -826,7 +826,7 @@ public: } ///Saves to disk only those spectra corresponding to mask values != 0 - bool sift_mask(std::string outfile, unsigned char* p){ + bool sift(std::string outfile, unsigned char* p){ // Assume X() = X, Y() = Y, Z() = Z. std::ofstream target(outfile.c_str(), std::ios::binary); diff --git a/stim/envi/bip.h b/stim/envi/bip.h index b9d85f2..a055369 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -836,8 +836,8 @@ public: } - ///Saves to disk only those spectra corresponding to mask values != 0 - bool sift_mask(std::string outfile, unsigned char* p){ + /// Saves to disk only those spectra corresponding to mask values != 0 + bool sift(std::string outfile, unsigned char* p){ // Assume X() = X, Y() = Y, Z() = Z. std::ofstream target(outfile.c_str(), std::ios::binary); diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index f13c3e4..0f3977c 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -759,8 +759,8 @@ public: return true; } - ///Saves to disk only those spectra corresponding to mask values != 0 - bool sift_mask(std::string outfile, unsigned char* p){ + /// Saves to disk only those spectra corresponding to mask values != 0 + bool sift(std::string outfile, unsigned char* p){ std::ofstream target(outfile.c_str(), std::ios::binary); // open a band (XY plane) unsigned XY = X() * Y(); //Number of XY pixels @@ -788,6 +788,57 @@ public: return true; } + /// Generates a spectral image from a matrix of spectral values in lexicographic order and a mask + bool unsift(std::string outfile, unsigned char* p, unsigned int samples, unsigned int lines){ + + //create a binary output stream + std::ofstream target(outfile.c_str(), std::ios::binary); + + //make sure that there's only one line + if(Y() != 1){ + std::cout<<"ERROR in stim::bsq::sift() - number of lines does not equal 1"<(unsifted), sizeof(T) * XY); + } + + return true; + } + /// Calculate the mean band value (average along B) at each pixel location. diff --git a/stim/envi/envi.h b/stim/envi/envi.h index 3a10635..f73bf24 100644 --- a/stim/envi/envi.h +++ b/stim/envi/envi.h @@ -373,32 +373,48 @@ public: } /// sift-mask saves in an array only those spectra corresponding to nonzero values of the mask. - bool sift_mask(std::string outfile, unsigned char* p) + bool sift(std::string outfile, unsigned char* p) { + //calculate the number of non-zero values in the mask + unsigned int nnz = 0; + unsigned int npixels = header.lines * header.samples; + for(unsigned int i = 0; i < npixels; i++) + if( p[i] > 0 ) nnz++; + + //create a new header + envi_header new_header = header; + + //set the number of lines to 1 (this is a matrix with 1 line and N samples) + new_header.lines = 1; + new_header.samples = nnz; + new_header.save(outfile + ".hdr"); + + std::cout<<"Saved: "<*)file)->sift_mask(outfile, p); + return ((bsq*)file)->sift(outfile, p); else if (header.data_type == envi_header::float64) - return ((bsq*)file)->sift_mask(outfile, p); + return ((bsq*)file)->sift(outfile, p); else std::cout << "ERROR: unidentified data type" << std::endl; } else if (header.interleave == envi_header::BIL){ //if the infile is bil file if (header.data_type == envi_header::float32) - return ((bil*)file)->sift_mask(outfile, p); + return ((bil*)file)->sift(outfile, p); else if (header.data_type == envi_header::float64) - return ((bil*)file)->sift_mask(outfile, p); + return ((bil*)file)->sift(outfile, p); else std::cout << "ERROR: unidentified data type" << std::endl; } else if (header.interleave == envi_header::BIP){ //if the infile is bip file if (header.data_type == envi_header::float32) - return ((bip*)file)->sift_mask(outfile, p); + return ((bip*)file)->sift(outfile, p); else if (header.data_type == envi_header::float64) - return ((bip*)file)->sift_mask(outfile, p); + return ((bip*)file)->sift(outfile, p); else std::cout << "ERROR: unidentified data type" << std::endl; } @@ -407,9 +423,48 @@ public: std::cout << "ERROR: unidentified file type" << std::endl; exit(1); } + + return false; } + bool unsift(std::string outfile, unsigned char* mask, unsigned int samples, unsigned int lines){ + + //create a new header + envi_header new_header = header; + + //set the number of lines and samples in the output file (that's all that changes) + new_header.lines = lines; + new_header.samples = samples; + new_header.save(outfile + ".hdr"); + + + if (header.interleave == envi_header::BSQ){ //if the infile is bsq file + if (header.data_type == envi_header::float32) + return ((bsq*)file)->unsift(outfile, mask, samples, lines); + else if (header.data_type == envi_header::float64) + return ((bsq*)file)->unsift(outfile, mask, samples, lines); + else + std::cout << "ERROR: unidentified data type" << std::endl; + } + + else if (header.interleave == envi_header::BIL){ //if the infile is bil file + + std::cout << "ERROR in stim::envi::unsift - BIL files aren't supported yet" << std::endl; + } + + else if (header.interleave == envi_header::BIP){ //if the infile is bip file + + std::cout << "ERROR in stim::envi::unsift - BIP files aren't supported yet" << std::endl; + } + + else{ + std::cout << "ERROR: unidentified file type" << std::endl; + exit(1); + } + + } + /// Compute the ratio of two baseline-corrected peaks. The result is stored in a pre-allocated array. /// @param lb1 is the label value for the left baseline point for the first peak (numerator) -- libgit2 0.21.4