diff --git a/envi/bsq.h b/envi/bsq.h index 10a8bf7..05018b3 100644 --- a/envi/bsq.h +++ b/envi/bsq.h @@ -85,8 +85,8 @@ public: getSlice(p, 2, page); } -// free(p1); -// free(p2); + free(p1); + free(p2); return true; } @@ -212,6 +212,42 @@ public: target.close(); return true; } + + // normalize the BSQ file + bool normalize(std::string outname, double band) + { + unsigned int B = header.bands; //calculate the number of bands + unsigned int XY = header.samples * header.lines; //calculate the number of pixels in a band + unsigned int S = XY * sizeof(T); //calculate the number of bytes in a band + + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file + std::string headername = outname + ".hdr"; //the header file name + + T * b; //pointers to the certain wavelength band + T * c; //pointer to the current image + + b = (T*)malloc( S ); //memory allocation + c = (T*)malloc( S ); + + getBand(b, band); //get the certain band into memory + + for(unsigned j = 0; j < B; j++) + { + band_index(c, j); //get the current band into memory + for(unsigned i = 0; i < XY; i++) + { + c[i] = c[i] / b[i]; + } + target.write(reinterpret_cast(c), S); //write normalized data into destination + } + + header.save(headername); //save the new header file + + free(b); + free(c); + target.close(); + return true; + } }; -- libgit2 0.21.4