Changeset 1217
- Timestamp:
- Jul 14, 2004, 1:23:42 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageManip.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageManip.c
r1212 r1217 1 /** @file tst_psImage .c1 /** @file tst_psImageManip.c 2 2 * 3 * @brief Contains the tests for psImage .[ch]3 * @brief Contains the tests for psImageManip.[ch] 4 4 * 5 5 * 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-07-1 3 01:37:59$8 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-07-14 23:23:42 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 16 #include <string.h> 17 17 #include <stdlib.h> 18 #include <string.h> // for memset 18 19 19 20 #include "psTest.h" … … 24 25 static int testImageClipNAN(void); 25 26 static int testImageOverlay(void); 27 static int testImageRebin(void); 26 28 27 29 testDescription tests[] = { … … 29 31 {testImageClipNAN,572,"psImageClipNAN",0,false}, 30 32 {testImageOverlay,573,"psImageOverlay",0,false}, 33 {testImageRebin,559,"psImageRebin",0,false}, 31 34 {NULL} 32 35 }; … … 460 463 return 0; 461 464 } 465 466 static int testImageRebin(void) 467 { 468 469 /* 470 This function shall generate a rescaled version of a psImage structure derived from a specified statistics method. 471 */ 472 473 psImage* in = NULL; 474 psImage* out = NULL; 475 psImage* out2 = NULL; 476 psImage* meanTruth = NULL; 477 psImage* maxTruth = NULL; 478 psStats stats; 479 480 /* 481 Verify the returned psImage structure contains expected values, if the input parameter input contains known data, the input scale is a known value with a known statistical method specified in stats. Cases should include at least two different scales and statistical methods. Comparison of expected values should include a delta to allow testing on different platforms. 482 */ 483 484 in = psImageAlloc(16,16,PS_TYPE_F32); 485 meanTruth = psImageAlloc(4,4,PS_TYPE_F32); 486 maxTruth = psImageAlloc(6,6,PS_TYPE_F32); 487 memset(meanTruth->data.F32[0],0,sizeof(psF32)*4*4); 488 memset(maxTruth->data.F32[0],0,sizeof(psF32)*6*6); 489 490 for (int row = 0; row<16; row++) { 491 psF32* inRow = in->data.F32[row]; 492 psF32* meanTruthRow = meanTruth->data.F32[row/4]; 493 psF32* maxTruthRow = maxTruth->data.F32[row/3]; 494 for (int col = 0; col<16; col++) { 495 inRow[col] = row + col; 496 meanTruthRow[col/4] += row + col; 497 if (maxTruthRow[col/3] < row + col) { 498 maxTruthRow[col/3] = row+col; 499 } 500 } 501 } 502 for (int row = 0; row<4; row++) { 503 psF32* meanTruthRow = meanTruth->data.F32[row]; 504 for (int col = 0; col<4; col++) { 505 meanTruthRow[col] /= 16; 506 } 507 } 508 509 stats.options = PS_STAT_SAMPLE_MEAN; 510 out = psImageRebin(NULL,in,4,&stats); 511 512 if (out == NULL) { 513 psError(__func__,"psImageRebin returned a NULL pointer!?"); 514 return 1; 515 } 516 517 if (out->numRows != 4 || out->numCols != 4) { 518 psError(__func__,"psImageRebin didn't produce the proper size image (%d x %d).", 519 out->numCols, out->numRows); 520 return 2; 521 } 522 523 for (int row = 0; row<4; row++) { 524 psF32* outRow = out->data.F32[row]; 525 psF32* truthRow = meanTruth->data.F32[row]; 526 for (int col = 0; col<4; col++) { 527 if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) { 528 psError(__func__,"psImageRebin didn't produce the proper result at (%d,%d) [%f vs %f].", 529 col,row,outRow[col],truthRow[col]); 530 return 3; 531 } 532 } 533 } 534 535 stats.options = PS_STAT_MAX; 536 out2 = psImageRebin(out,in,3,&stats); 537 538 // Verify the returned psImage structure is equal to the input parameter out if specified. 539 if (out != out2) { 540 psError(__func__,"psImageRebin didn't recycle a psImage properly!?"); 541 return 7; 542 } 543 544 if (out == NULL) { 545 psError(__func__,"psImageRebin returned a NULL pointer!?"); 546 return 4; 547 } 548 549 if (out->numRows != 6 || out->numCols != 6) { 550 psError(__func__,"psImageRebin didn't produce the proper size image (%d x %d).", 551 out->numCols, out->numRows); 552 return 5; 553 } 554 555 for (int row = 0; row<6; row++) { 556 psF32* outRow = out->data.F32[row]; 557 psF32* truthRow = maxTruth->data.F32[row]; 558 for (int col = 0; col<6; col++) { 559 if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) { 560 psError(__func__,"psImageRebin didn't produce the proper result at (%d,%d) [%f vs %f].", 561 col,row,outRow[col],truthRow[col]); 562 return 6; 563 } 564 } 565 } 566 567 // Verify the returned psImage structure is null and program execution 568 // doesn't stop, if the input parameter input is null. 569 570 out2 = psImageRebin(NULL,NULL,1,&stats); 571 572 if (out2 != NULL) { 573 psError(__func__,"psImageRebin returned an image though the input was NULL!?"); 574 return 8; 575 } 576 577 // Verify the returned psImage structure is null and program execution 578 // doesn't stop, if the input parameter scale is less than or equal to zero. 579 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 580 out2 = psImageRebin(NULL,in,0,&stats); 581 582 if (out2 != NULL) { 583 psError(__func__,"psImageRebin returned an image though the scale was zero!?"); 584 return 9; 585 } 586 587 // Verify the returned psImage structure is null and program execution 588 // doesn't stop, if the input parameter stats is null. 589 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 590 out2 = psImageRebin(NULL,in,1,NULL); 591 592 if (out2 != NULL) { 593 psError(__func__,"psImageRebin returned an image though the stats was NULL!?"); 594 return 10; 595 } 596 597 // Verify the returned psImage structure is null and program execution 598 // doesn't stop, if the input parameter psStats structure member options 599 // is zero or any value which doesn't correspond to a valid statistical 600 // method. 601 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 602 stats.options = 0; 603 out2 = psImageRebin(NULL,in,1,&stats); 604 605 if (out2 != NULL) { 606 psError(__func__,"psImageRebin returned an image though the stats options was zero!?"); 607 return 11; 608 } 609 610 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 611 stats.options = PS_STAT_USE_RANGE; 612 out2 = psImageRebin(NULL,in,1,&stats); 613 614 if (out2 != NULL) { 615 psError(__func__,"psImageRebin returned an image though the stats options was PS_STAT_USE_RANGE!?"); 616 return 12; 617 } 618 619 // Verify the returned psImage structure is null and program execution 620 // doesn't stop, if the input parameter psStats structure member options 621 // specifies more than one valid statistical method. 622 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error."); 623 stats.options = PS_STAT_SAMPLE_MEAN + PS_STAT_MAX; 624 out2 = psImageRebin(NULL,in,1,&stats); 625 626 if (out2 != NULL) { 627 psError(__func__,"psImageRebin returned an image though the stats options was PS_STAT_SAMPLE_MEAN+PS_STAT_MAX!?"); 628 return 13; 629 } 630 631 632 psFree(in); 633 psFree(out); 634 psFree(meanTruth); 635 psFree(maxTruth); 636 637 return 0; 638 }
Note:
See TracChangeset
for help on using the changeset viewer.
