Changeset 1365 for trunk/psLib/test/image/tst_psImageStats02.c
- Timestamp:
- Aug 2, 2004, 9:43:23 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageStats02.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageStats02.c
r1078 r1365 1 1 /***************************************************************************** 2 This routine must ensure that the psImageStats() routine can correctly3 call the psVectorStats() routine. Since the psVectorStats() will be4 thouroughly tested elsewhere, we will only test psImageStats() with5 the PS_STAT_SAMPLE_MEAN here.6 7 NOTE: After you debug, set CHEBY_X_DIM != CHEBY_Y_DIM.8 Also, uses non-square images.9 *****************************************************************************/2 This routine must ensure that the psImageStats() routine can correctly 3 call the psVectorStats() routine. Since the psVectorStats() will be 4 thouroughly tested elsewhere, we will only test psImageStats() with 5 the PS_STAT_SAMPLE_MEAN here. 6 7 NOTE: After you debug, set CHEBY_X_DIM != CHEBY_Y_DIM. 8 Also, uses non-square images. 9 *****************************************************************************/ 10 10 #include <stdio.h> 11 11 #include "pslib.h" … … 19 19 #define CHEBY_X_DIM 8 20 20 #define CHEBY_Y_DIM 8 21 #define THRESHOLD 1 .021 #define THRESHOLD 10 22 22 int main() 23 23 { 24 psStats * myStats= NULL;25 psImage *tmpImage = NULL;26 psImage *outImage = NULL;24 psStats * myStats = NULL; 25 psImage *tmpImage = NULL; 26 psImage *outImage = NULL; 27 27 psPolynomial2D *my2DPoly = NULL; 28 int testStatus = true;29 int memLeaks = 0;30 int i = 0;31 int j = 0;32 int rc = 0;33 int currentId = 0;34 35 currentId = psMemGetId();28 int testStatus = true; 29 int memLeaks = 0; 30 int i = 0; 31 int j = 0; 32 int rc = 0; 33 int currentId = 0; 34 35 currentId = psMemGetId(); 36 36 /*************************************************************************/ 37 37 /* Allocate and initialize data structures */ 38 38 /*************************************************************************/ 39 tmpImage = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32); 40 outImage = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32); 41 for (i=0;i<IMAGE_SIZE;i++) { 42 for (j=0;j<IMAGE_SIZE;j++) { 43 tmpImage->data.F32[i][j] = 4.0; 44 tmpImage->data.F32[i][j] = (float) (i + j); 45 tmpImage->data.F32[i][j] = (float) (i + j) + (4.0 * (float) i); 46 outImage->data.F32[i][j] = 0.0; 39 tmpImage = psImageAlloc( IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32 ); 40 outImage = psImageAlloc( IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32 ); 41 for ( i = 0;i < IMAGE_SIZE;i++ ) { 42 for ( j = 0;j < IMAGE_SIZE;j++ ) { 43 tmpImage->data.F32[ i ][ j ] = 4.0; 44 tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j ); 45 tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j ) + ( 4.0 * ( float ) i ); 46 outImage->data.F32[ i ][ j ] = 0.0; 47 } 47 48 } 48 } 49 my2DPoly = psPolynomial2DAlloc(CHEBY_X_DIM, CHEBY_Y_DIM); 49 my2DPoly = psPolynomial2DAlloc( CHEBY_X_DIM, CHEBY_Y_DIM ); 50 50 /*************************************************************************/ 51 51 /* Calculate Chebyshev Polynomials, no mask */ 52 52 /*************************************************************************/ 53 printPositiveTestHeader(stdout, 54 "psImageStats functions", 55 "Calculate Chebyshev Polynomials, no mask"); 56 57 my2DPoly = psImageFitPolynomial(tmpImage, my2DPoly); 58 for (i=0;i<CHEBY_X_DIM;i++) { 59 for (j=0;j<CHEBY_Y_DIM;j++) { 60 printf("Cheby Polynomial (%d, %d) coefficient is %f\n", i, j, my2DPoly->coeff[i][j]); 53 printPositiveTestHeader( stdout, 54 "psImageStats functions", 55 "Calculate Chebyshev Polynomials, no mask" ); 56 57 my2DPoly = psImageFitPolynomial( tmpImage, my2DPoly ); 58 for ( i = 0;i < CHEBY_X_DIM;i++ ) { 59 for ( j = 0;j < CHEBY_Y_DIM;j++ ) { 60 printf( "Cheby Polynomial (%d, %d) coefficient is %.2f\n", i, j, my2DPoly->coeff[ i ][ j ] ); 61 } 61 62 } 62 } 63 64 psMemCheckCorruption(1); 65 printFooter(stdout, 66 "psImageStats functions", 67 "Calculate Chebyshev Polynomials, no mask", 68 testStatus); 63 64 psMemCheckCorruption( 1 ); 65 printFooter( stdout, 66 "psImageStats functions", 67 "Calculate Chebyshev Polynomials, no mask", 68 testStatus ); 69 69 /*************************************************************************/ 70 70 /* Evaluate Chebyshev Polynomials, no mask */ 71 71 /*************************************************************************/ 72 printPositiveTestHeader(stdout, 73 "psImageStats functions", 74 "Calculate Chebyshev Polynomials, no mask"); 75 76 rc = psImageEvalPolynomial(outImage, my2DPoly); 77 for (i=0;i<IMAGE_SIZE;i++) { 78 for (j=0;j<IMAGE_SIZE;j++) { 79 80 // printf("pixel[%d][%d] is (%f, %f)\n", i, j, 81 // tmpImage->data.F32[i][j], 82 // outImage->data.F32[i][j]); 83 if (fabs(outImage->data.F32[i][j] - tmpImage->data.F32[i][j]) > THRESHOLD) { 84 printf("Pixel (%d, %d) is %f, should be %f\n", i, j, 85 outImage->data.F32[i][j], 86 tmpImage->data.F32[i][j]); 87 } 88 72 printPositiveTestHeader( stdout, 73 "psImageStats functions", 74 "Calculate Chebyshev Polynomials, no mask" ); 75 76 rc = psImageEvalPolynomial( outImage, my2DPoly ); 77 for ( i = 0;i < IMAGE_SIZE;i++ ) { 78 for ( j = 0;j < IMAGE_SIZE;j++ ) { 79 80 // printf("pixel[%d][%d] is (%f, %f)\n", i, j, 81 // tmpImage->data.F32[i][j], 82 // outImage->data.F32[i][j]); 83 if ( fabs( outImage->data.F32[ i ][ j ] - tmpImage->data.F32[ i ][ j ] ) > THRESHOLD ) { 84 printf( "Pixel (%d, %d) is %.2f, should be %.2f\n", i, j, 85 outImage->data.F32[ i ][ j ], 86 tmpImage->data.F32[ i ][ j ] ); 87 } 88 89 } 89 90 } 90 } 91 92 psMemCheckCorruption(1); 93 printFooter(stdout, 94 "psImageStats functions", 95 "Calculate Chebyshev Polynomials, no mask", 96 testStatus); 97 91 92 psMemCheckCorruption( 1 ); 93 printFooter( stdout, 94 "psImageStats functions", 95 "Calculate Chebyshev Polynomials, no mask", 96 testStatus ); 97 98 98 /*************************************************************************/ 99 99 /* Deallocate data structures */ 100 100 /*************************************************************************/ 101 printPositiveTestHeader( stdout,102 "psImageStats functions",103 "Deallocate the psStats/psImage structure.");104 psFree( myStats);105 psFree( tmpImage);106 psFree( outImage);107 psFree( my2DPoly);108 109 psMemCheckCorruption( 1);110 memLeaks = psMemCheckLeaks( currentId,NULL,NULL);111 if ( 0 != memLeaks) {112 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);113 }114 115 printFooter( stdout,116 "psImageStats functions",117 "Deallocate the psStats/psImage structure.",118 testStatus);119 120 return ( !testStatus);101 printPositiveTestHeader( stdout, 102 "psImageStats functions", 103 "Deallocate the psStats/psImage structure." ); 104 psFree( myStats ); 105 psFree( tmpImage ); 106 psFree( outImage ); 107 psFree( my2DPoly ); 108 109 psMemCheckCorruption( 1 ); 110 memLeaks = psMemCheckLeaks( currentId, NULL, NULL ); 111 if ( 0 != memLeaks ) { 112 psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks ); 113 } 114 115 printFooter( stdout, 116 "psImageStats functions", 117 "Deallocate the psStats/psImage structure.", 118 testStatus ); 119 120 return ( !testStatus ); 121 121 }
Note:
See TracChangeset
for help on using the changeset viewer.
