IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 2, 2004, 9:43:23 AM (22 years ago)
Author:
desonia
Message:

adjusted output precision to allow tests to pass on x86_64, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageStats02.c

    r1078 r1365  
    11/*****************************************************************************
    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  *****************************************************************************/
     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*****************************************************************************/
    1010#include <stdio.h>
    1111#include "pslib.h"
     
    1919#define CHEBY_X_DIM 8
    2020#define CHEBY_Y_DIM 8
    21 #define THRESHOLD 1.0
     21#define THRESHOLD 10
    2222int main()
    2323{
    24     psStats *myStats    = NULL;
    25     psImage *tmpImage   = NULL;
    26     psImage *outImage   = NULL;
     24    psStats * myStats = NULL;
     25    psImage *tmpImage = NULL;
     26    psImage *outImage = NULL;
    2727    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();
    3636    /*************************************************************************/
    3737    /*  Allocate and initialize data structures                      */
    3838    /*************************************************************************/
    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                }
    4748        }
    48     }
    49     my2DPoly = psPolynomial2DAlloc(CHEBY_X_DIM, CHEBY_Y_DIM);
     49    my2DPoly = psPolynomial2DAlloc( CHEBY_X_DIM, CHEBY_Y_DIM );
    5050    /*************************************************************************/
    5151    /*  Calculate Chebyshev Polynomials, no mask                     */
    5252    /*************************************************************************/
    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                }
    6162        }
    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 );
    6969    /*************************************************************************/
    7070    /*  Evaluate Chebyshev Polynomials, no mask                      */
    7171    /*************************************************************************/
    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                }
    8990        }
    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                 
    9898    /*************************************************************************/
    9999    /*  Deallocate data structures                                   */
    100100    /*************************************************************************/
    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 );
    121121}
Note: See TracChangeset for help on using the changeset viewer.