Commit 93503ec6334b0ccc5b50360f3ff0c951768e0274

Authored by David Mayerich
1 parent 81e0d221

allowed masking during normalization

Showing 4 changed files with 21 additions and 9 deletions   Show diff stats
envi/bil.h
... ... @@ -309,7 +309,7 @@ public:
309 309 }
310 310  
311 311 // normalize the BIL file
312   - bool normalize(std::string outname, double w)
  312 + bool normalize(std::string outname, double w, double t = 0.0)
313 313 {
314 314 unsigned int B = R[2]; //calculate the number of bands
315 315 unsigned int Y = R[1];
... ... @@ -337,7 +337,10 @@ public:
337 337 {
338 338 for(unsigned m = 0; m < X; m++)
339 339 {
340   - c[m + i * X] = c[m + i * X] / b[m + j * X];
  340 + if( b[m + j * X] < t )
  341 + c[m + i * X] = (T)0.0;
  342 + else
  343 + c[m + i * X] = c[m + i * X] / b[m + j * X];
341 344 }
342 345 }
343 346 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
... ...
envi/bip.h
... ... @@ -401,7 +401,7 @@ public:
401 401 }
402 402  
403 403 // normalize the BIP file
404   - bool normalize(std::string outname, double w)
  404 + bool normalize(std::string outname, double w, double t = 0.0)
405 405 {
406 406 unsigned int B = R[2]; //calculate the number of bands
407 407 unsigned int Y = R[1];
... ... @@ -431,7 +431,10 @@ public:
431 431 unsigned iB = i * B;
432 432 for(unsigned m = 0; m < B; m++)
433 433 {
434   - c[m + iB] = c[m + iB] / b[i + jX]; //perform normalization
  434 + if( b[i+jX] < t )
  435 + c[m + iB] = (T)0.0;
  436 + else
  437 + c[m + iB] = c[m + iB] / b[i + jX]; //perform normalization
435 438 }
436 439 }
437 440 target.write(reinterpret_cast<const char*>(c), L); //write normalized data into destination
... ...
envi/bsq.h
... ... @@ -252,7 +252,10 @@ public:
252 252 }
253 253  
254 254 // normalize the BSQ file
255   - bool normalize(std::string outname, double w)
  255 + // outname - output file name
  256 + // w - band to normalize to
  257 + // t - threshold (if w<t, all pixel bands are set to zero)
  258 + bool normalize(std::string outname, double w, double t = 0.0)
256 259 {
257 260 unsigned int B = R[2]; //calculate the number of bands
258 261 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band
... ... @@ -274,7 +277,10 @@ public:
274 277 band_index(c, j); //get the current band into memory
275 278 for(unsigned i = 0; i < XY; i++)
276 279 {
277   - c[i] = c[i] / b[i];
  280 + if(b[i] < t)
  281 + c[i] = (T)0.0;
  282 + else
  283 + c[i] = c[i] / b[i];
278 284 }
279 285 target.write(reinterpret_cast<const char*>(c), S); //write normalized data into destination
280 286 }
... ...
envi/envi.h
... ... @@ -96,13 +96,13 @@ public:
96 96 }
97 97  
98 98 //perform normalization
99   - bool normalize(std::string outfile, double band){
  99 + bool normalize(std::string outfile, double band, double threshold = 0.0){
100 100  
101 101 if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
102 102 if(header.data_type ==envi_header::float32)
103   - return ((bsq<float>*)file)->normalize(outfile, band);
  103 + return ((bsq<float>*)file)->normalize(outfile, band, threshold);
104 104 else if(header.data_type == envi_header::float64)
105   - return ((bsq<double>*)file)->normalize(outfile,band);
  105 + return ((bsq<double>*)file)->normalize(outfile,band, threshold);
106 106 else
107 107 std::cout<<"ERROR: unidentified data type"<<std::endl;
108 108 }
... ...