Authored by heziqi
1 parent f47168a2

Ziqi completed height2heigth area2height area2area ratio

Showing 4 changed files with 311 additions and 91 deletions
envi/bil.h

 ... ... @@ -403,17 +403,16 @@ public: 403 403 } 404 404 //untested 405 405 //providing the left and the right bound wavelength, return baseline-corrected band height 406 - bool height(double lb, double rb, double bandwavelength){ 406 + bool height(double lb, double rb, double bandwavelength, T* result){ 407 407 408 408 T* lp; 409 409 T* rp; 410 - T* result; 411 - 412 - lp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); //memory allocation 413 - rp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); 414 - result = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); 410 + unsigned XY = R[0] * R[1]; 411 + unsigned S = XY * sizeof(T); 412 + lp = (T*) malloc(S); //memory allocation 413 + rp = (T*) malloc(S); 415 414 416 - band(lp, lb); //get the data of the left bounbd and the right bound 415 + band(lp, lb); 417 416 band(rp, rb); 418 417 419 418 baseline_band(lb, rb, lp, rp, bandwavelength, result); ... ... @@ -421,14 +420,14 @@ public: 421 420 return true; 422 421 } 423 422 423 + 424 424 //calculate the area between two bound point(including baseline correction) 425 - bool area(double lb, double rb){ 425 + bool area(double lb, double rb, double lab, double rab, T* result){ 426 426 427 427 T* lp; //left band pointer 428 428 T* rp; //right band pointer 429 429 T* cur; //current band 1 430 430 T* cur2; //current band 2 431 - T* result; //area result 432 431 433 432 unsigned XY = R[0] * R[1]; 434 433 unsigned S = XY * sizeof(T); ... ... @@ -437,7 +436,6 @@ public: 437 436 rp = (T*) malloc(S); 438 437 cur = (T*) malloc(S); 439 438 cur2 = (T*) malloc(S); 440 - result = (T*) malloc(S); 441 439 442 440 memset(result, (char)0, S); 443 441 ... ... @@ -460,10 +458,10 @@ public: 460 458 } 461 459 462 460 //get the position of lb and rb 463 - while (lb >= w[ai]){ 461 + while (lab >= w[ai]){ 464 462 ai++; 465 463 } 466 - while (rb <= w[bi]){ 464 + while (rab <= w[bi]){ 467 465 bi--; 468 466 } 469 467 ... ... @@ -471,13 +469,15 @@ public: 471 469 band(rp, rb); 472 470 473 471 //calculate the beginning and the ending part 474 - baseline_band(lb, rb, lp, rp, w[bi], cur); //ending part 472 + baseline_band(lb, rb, lp, rp, rab, cur2); //ending part 473 + baseline_band(lb, rb, lp, rp, w[bi], cur); 475 474 for(unsigned j = 0; j < XY; j++){ 476 - result[j] += (rb - w[bi]) * cur[j] / 2.0; 475 + result[j] += (rab - w[bi]) * (cur[j] + cur2[j]) / 2.0; 477 476 } 478 - baseline_band(lb, rb, lp, rp, w[ai], cur); //beginnning part 477 + baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part 478 + baseline_band(lb, rb, lp, rp, w[ai], cur); 479 479 for(unsigned j = 0; j < XY; j++){ 480 - result[j] += (w[ai] - lb) * cur[j] / 2.0; 480 + result[j] += (w[ai] - lab) * (cur[j] + cur2[j]) / 2.0; 481 481 } 482 482 //calculate the area 483 483 ai++; ... ... @@ -490,20 +490,69 @@ public: 490 490 } 491 491 std::swap(cur,cur2); //swap the band pointers 492 492 } 493 - ///////////////for testing use 494 - std::ofstream text("area_result.txt",std::ios::out); 495 - for (unsigned i = 0; i < 640; i++) 496 - { 497 - for (unsigned j = 0; j < 384; j++) 498 - { 499 - text<
envi/bip.h

 ... ... @@ -490,17 +490,16 @@ public: 490 490 } 491 491 //untested 492 492 //providing the left and the right bound wavelength, return baseline-corrected band height 493 - bool height(double lb, double rb, double bandwavelength){ 493 + bool height(double lb, double rb, double bandwavelength, T* result){ 494 494 495 495 T* lp; 496 496 T* rp; 497 - T* result; 498 - 499 - lp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); //memory allocation 500 - rp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); 501 - result = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); 497 + unsigned XY = R[0] * R[1]; 498 + unsigned S = XY * sizeof(T); 499 + lp = (T*) malloc(S); //memory allocation 500 + rp = (T*) malloc(S); 502 501 503 - band(lp, lb); //get the data of the left bounbd and the right bound 502 + band(lp, lb); 504 503 band(rp, rb); 505 504 506 505 baseline_band(lb, rb, lp, rp, bandwavelength, result); ... ... @@ -510,13 +509,12 @@ public: 510 509 511 510 512 511 //calculate the area between two bound point(including baseline correction) 513 - bool area(double lb, double rb){ 512 + bool area(double lb, double rb, double lab, double rab, T* result){ 514 513 515 514 T* lp; //left band pointer 516 515 T* rp; //right band pointer 517 516 T* cur; //current band 1 518 517 T* cur2; //current band 2 519 - T* result; //area result 520 518 521 519 unsigned XY = R[0] * R[1]; 522 520 unsigned S = XY * sizeof(T); ... ... @@ -525,7 +523,6 @@ public: 525 523 rp = (T*) malloc(S); 526 524 cur = (T*) malloc(S); 527 525 cur2 = (T*) malloc(S); 528 - result = (T*) malloc(S); 529 526 530 527 memset(result, (char)0, S); 531 528 ... ... @@ -548,10 +545,10 @@ public: 548 545 } 549 546 550 547 //get the position of lb and rb 551 - while (lb >= w[ai]){ 548 + while (lab >= w[ai]){ 552 549 ai++; 553 550 } 554 - while (rb <= w[bi]){ 551 + while (rab <= w[bi]){ 555 552 bi--; 556 553 } 557 554 ... ... @@ -559,13 +556,15 @@ public: 559 556 band(rp, rb); 560 557 561 558 //calculate the beginning and the ending part 562 - baseline_band(lb, rb, lp, rp, w[bi], cur); //ending part 559 + baseline_band(lb, rb, lp, rp, rab, cur2); //ending part 560 + baseline_band(lb, rb, lp, rp, w[bi], cur); 563 561 for(unsigned j = 0; j < XY; j++){ 564 - result[j] += (rb - w[bi]) * cur[j] / 2.0; 562 + result[j] += (rab - w[bi]) * (cur[j] + cur2[j]) / 2.0; 565 563 } 566 - baseline_band(lb, rb, lp, rp, w[ai], cur); //beginnning part 564 + baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part 565 + baseline_band(lb, rb, lp, rp, w[ai], cur); 567 566 for(unsigned j = 0; j < XY; j++){ 568 - result[j] += (w[ai] - lb) * cur[j] / 2.0; 567 + result[j] += (w[ai] - lab) * (cur[j] + cur2[j]) / 2.0; 569 568 } 570 569 //calculate the area 571 570 ai++; ... ... @@ -578,20 +577,68 @@ public: 578 577 } 579 578 std::swap(cur,cur2); //swap the band pointers 580 579 } 581 - ///////////////for testing use 582 - std::ofstream text("area_result.txt",std::ios::out); 583 - for (unsigned i = 0; i < 640; i++) 584 - { 585 - for (unsigned j = 0; j < 384; j++) 586 - { 587 - text<
envi/bsq.h

 ... ... @@ -50,7 +50,11 @@ public: 50 50 return false; 51 51 } 52 52 53 - getSlice(p, 2, page); 53 + file.seekg(R[0] * R[1] * page * sizeof(T), std::ios::beg); 54 + 55 + file.read((char *)p, sizeof(T) * R[0] * R[1]); 56 + 57 +// getSlice(p, 2, page); 54 58 return true; 55 59 } 56 60 ... ... @@ -93,7 +97,7 @@ public: 93 97 } 94 98 else //if the wavelength is equal to a wavelength in header file 95 99 { 96 - getSlice(p, 2, page); 100 + band_index(p, page); 97 101 } 98 102 99 103 return true; ... ... @@ -325,17 +329,16 @@ public: 325 329 } 326 330 //untested 327 331 //providing the left and the right bound wavelength, return baseline-corrected band height 328 - bool height(double lb, double rb, double bandwavelength){ 332 + bool height(double lb, double rb, double bandwavelength, T* result){ 329 333 330 334 T* lp; 331 335 T* rp; 332 - T* result; 333 - 334 - lp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); //memory allocation 335 - rp = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); 336 - result = (T*) malloc(sizeof(R[0] * R[1] * sizeof(T))); 336 + unsigned XY = R[0] * R[1]; 337 + unsigned S = XY * sizeof(T); 338 + lp = (T*) malloc(S); //memory allocation 339 + rp = (T*) malloc(S); 337 340 338 - band(lp, lb); //get the data of the left bounbd and the right bound 341 + band(lp, lb); 339 342 band(rp, rb); 340 343 341 344 baseline_band(lb, rb, lp, rp, bandwavelength, result); ... ... @@ -345,13 +348,12 @@ public: 345 348 346 349 347 350 //calculate the area between two bound point(including baseline correction) 348 - bool area(double lb, double rb){ 351 + bool area(double lb, double rb, double lab, double rab, T* result){ 349 352 350 353 T* lp; //left band pointer 351 354 T* rp; //right band pointer 352 355 T* cur; //current band 1 353 356 T* cur2; //current band 2 354 - T* result; //area result 355 357 356 358 unsigned XY = R[0] * R[1]; 357 359 unsigned S = XY * sizeof(T); ... ... @@ -360,7 +362,6 @@ public: 360 362 rp = (T*) malloc(S); 361 363 cur = (T*) malloc(S); 362 364 cur2 = (T*) malloc(S); 363 - result = (T*) malloc(S); 364 365 365 366 memset(result, (char)0, S); 366 367 ... ... @@ -383,10 +384,10 @@ public: 383 384 } 384 385 385 386 //get the position of lb and rb 386 - while (lb >= w[ai]){ 387 + while (lab >= w[ai]){ 387 388 ai++; 388 389 } 389 - while (rb <= w[bi]){ 390 + while (rab <= w[bi]){ 390 391 bi--; 391 392 } 392 393 ... ... @@ -394,14 +395,17 @@ public: 394 395 band(rp, rb); 395 396 396 397 //calculate the beginning and the ending part 397 - baseline_band(lb, rb, lp, rp, w[bi], cur); //ending part 398 + baseline_band(lb, rb, lp, rp, rab, cur2); //ending part 399 + baseline_band(lb, rb, lp, rp, w[bi], cur); 398 400 for(unsigned j = 0; j < XY; j++){ 399 - result[j] += (rb - w[bi]) * cur[j] / 2.0; 401 + result[j] += (rab - w[bi]) * (cur[j] + cur2[j]) / 2.0; 400 402 } 401 - baseline_band(lb, rb, lp, rp, w[ai], cur); //beginnning part 403 + baseline_band(lb, rb, lp, rp, lab, cur2); //beginnning part 404 + baseline_band(lb, rb, lp, rp, w[ai], cur); 402 405 for(unsigned j = 0; j < XY; j++){ 403 - result[j] += (w[ai] - lb) * cur[j] / 2.0; 406 + result[j] += (w[ai] - lab) * (cur[j] + cur2[j]) / 2.0; 404 407 } 408 + 405 409 //calculate the area 406 410 ai++; 407 411 for(unsigned i = ai; i <= bi ;i++) ... ... @@ -413,21 +417,68 @@ public: 413 417 } 414 418 std::swap(cur,cur2); //swap the band pointers 415 419 } 416 - ///////////////for testing use 417 - std::ofstream text("area_result.txt",std::ios::out); 418 - for (unsigned i = 0; i < 640; i++) 419 - { 420 - for (unsigned j = 0; j < 384; j++) 421 - { 422 - text<
envi/envi.h

 ... ... @@ -310,31 +310,104 @@ public: 310 310 return false; 311 311 } 312 312 313 - //do baseline correction and caculate the area between two bounds 314 - bool area(double lb, double rb){ 313 + //peak height to peak height ratio 314 + bool ph_to_ph(double lb1, double rb1, double pos1, double lb2, double rb2, double pos2, void * result){ 315 315 if(header.interleave == envi_header::BSQ){ //if the infile is bsq file 316 316 if(header.data_type ==envi_header::float32) 317 - return ((bsq*)file)->area(lb, rb); 317 + return ((bsq*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result); 318 318 else if(header.data_type == envi_header::float64) 319 - return ((bsq*)file)->area(lb, rb); 319 + return ((bsq*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result); 320 320 else 321 321 std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); 326 + return ((bil*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result); 327 327 else if(header.data_type == envi_header::float64) 328 - return ((bil*)file)->area(lb, rb); 328 + return ((bil*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result); 329 329 else 330 330 std::cout<<"ERROR: unidentified data type"<*)file)->area(lb, rb); 335 + return ((bip*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (float*)result); 336 336 else if(header.data_type == envi_header::float64) 337 - return ((bip*)file)->area(lb, rb); 337 + return ((bip*)file)->ph_to_ph(lb1, rb1, pos1, lb2, rb2, pos2, (double*)result); 338 + else 339 + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result); 354 + else if(header.data_type == envi_header::float64) 355 + return ((bsq*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result); 356 + else 357 + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result); 363 + else if(header.data_type == envi_header::float64) 364 + return ((bil*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result); 365 + else 366 + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (float*)result); 372 + else if(header.data_type == envi_header::float64) 373 + return ((bip*)file)->pa_to_ph(lb1, rb1, lab1, rab1, lb2, rb2, pos, (double*)result); 374 + else 375 + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result); 391 + else if(header.data_type == envi_header::float64) 392 + return ((bsq*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result); 393 + else 394 + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result); 400 + else if(header.data_type == envi_header::float64) 401 + return ((bil*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result); 402 + else 403 + std::cout<<"ERROR: unidentified data type"<*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (float*)result); 409 + else if(header.data_type == envi_header::float64) 410 + return ((bip*)file)->pa_to_pa(lb1, rb1, lab1, rab1, lb2, rb2, lab2, rab2, (double*)result); 338 411 else 339 412 std::cout<<"ERROR: unidentified data type"<