Commit 089d9c81632d1f66169d6ce6aaf8b3ec4227157b

Authored by heziqi
1 parent 0c748c81

Ziqi added normalize function in BSQ

Showing 1 changed file with 38 additions and 2 deletions   Show diff stats
envi/bsq.h
... ... @@ -85,8 +85,8 @@ public:
85 85 getSlice(p, 2, page);
86 86 }
87 87  
88   -// free(p1);
89   -// free(p2);
  88 + free(p1);
  89 + free(p2);
90 90 return true;
91 91 }
92 92  
... ... @@ -212,6 +212,42 @@ public:
212 212 target.close();
213 213 return true;
214 214 }
  215 +
  216 + // normalize the BSQ file
  217 + bool normalize(std::string outname, double band)
  218 + {
  219 + unsigned int B = header.bands; //calculate the number of bands
  220 + unsigned int XY = header.samples * header.lines; //calculate the number of pixels in a band
  221 + unsigned int S = XY * sizeof(T); //calculate the number of bytes in a band
  222 +
  223 + std::ofstream target(outname.c_str(), std::ios::binary); //open the target binary file
  224 + std::string headername = outname + ".hdr"; //the header file name
  225 +
  226 + T * b; //pointers to the certain wavelength band
  227 + T * c; //pointer to the current image
  228 +
  229 + b = (T*)malloc( S ); //memory allocation
  230 + c = (T*)malloc( S );
  231 +
  232 + getBand(b, band); //get the certain band into memory
  233 +
  234 + for(unsigned j = 0; j < B; j++)
  235 + {
  236 + band_index(c, j); //get the current band into memory
  237 + for(unsigned i = 0; i < XY; i++)
  238 + {
  239 + c[i] = c[i] / b[i];
  240 + }
  241 + target.write(reinterpret_cast<const char*>(c), S); //write normalized data into destination
  242 + }
  243 +
  244 + header.save(headername); //save the new header file
  245 +
  246 + free(b);
  247 + free(c);
  248 + target.close();
  249 + return true;
  250 + }
215 251  
216 252  
217 253 };
... ...