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_psImageStats01.c

    r1234 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  *****************************************************************************/
     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*****************************************************************************/
    77#include <stdio.h>
    88#include "pslib.h"
     
    1717int main()
    1818{
    19     psStats *myStats    = NULL;
    20     psStats *myStats2   = NULL;
    21     psImage *tmpImage   = NULL;
    22     psImage *tmpMask    = NULL;
    23     int testStatus      = true;
    24     int memLeaks        = 0;
    25     int nb              = 0;
    26     int i               = 0;
    27     int j               = 0;
    28     int IMAGE_X_SIZE    = 0;
    29     int IMAGE_Y_SIZE    = 0;
    30     int currentId       = 0;
    31 
    32     currentId       = psMemGetId();
    33     for (nb=0;nb<6;nb++) {
    34         if (nb == 0) {
    35             IMAGE_X_SIZE = 1;
    36             IMAGE_Y_SIZE = 1;
     19    psStats * myStats = NULL;
     20    psStats *myStats2 = NULL;
     21    psImage *tmpImage = NULL;
     22    psImage *tmpMask = NULL;
     23    int testStatus = true;
     24    int memLeaks = 0;
     25    int nb = 0;
     26    int i = 0;
     27    int j = 0;
     28    int IMAGE_X_SIZE = 0;
     29    int IMAGE_Y_SIZE = 0;
     30    int currentId = 0;
     31   
     32    currentId = psMemGetId();
     33    for ( nb = 0;nb < 6;nb++ ) {
     34            if ( nb == 0 ) {
     35                    IMAGE_X_SIZE = 1;
     36                    IMAGE_Y_SIZE = 1;
     37                }
     38            if ( nb == 1 ) {
     39                    IMAGE_X_SIZE = 1;
     40                    IMAGE_Y_SIZE = N;
     41                }
     42            if ( nb == 2 ) {
     43                    IMAGE_X_SIZE = N;
     44                    IMAGE_Y_SIZE = 1;
     45                }
     46            if ( nb == 3 ) {
     47                    IMAGE_X_SIZE = N;
     48                    IMAGE_Y_SIZE = N;
     49                }
     50            if ( nb == 4 ) {
     51                    IMAGE_X_SIZE = N;
     52                    IMAGE_Y_SIZE = M;
     53                }
     54            if ( nb == 5 ) {
     55                    IMAGE_X_SIZE = M;
     56                    IMAGE_Y_SIZE = N;
     57                }
     58            printf( "*******************************\n" );
     59            printf( "* IMAGE SIZE is (%d by %d)\n", IMAGE_X_SIZE, IMAGE_Y_SIZE );
     60            printf( "*******************************\n" );
     61           
     62            /*************************************************************************/
     63            /*  Allocate and initialize data structures                      */
     64            /*************************************************************************/
     65            tmpImage = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32 );
     66           
     67            for ( i = 0;i < tmpImage->numRows;i++ ) {
     68                    for ( j = 0;j < tmpImage->numCols;j++ ) {
     69                            tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j );
     70                        }
     71                }
     72            tmpMask = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8 );
     73            for ( i = 0;i < tmpMask->numRows;i++ ) {
     74                    for ( j = 0;j < tmpMask->numCols;j++ ) {
     75                            if ( ( i > ( tmpMask->numRows / 2 ) ) &&
     76                                    ( j > ( tmpMask->numCols / 2 ) ) ) {
     77                                    tmpMask->data.U8[ i ][ j ] = 1;
     78                                } else {
     79                                    tmpMask->data.U8[ i ][ j ] = 0;
     80                                }
     81                        }
     82                }
     83               
     84            myStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN );
     85            /*************************************************************************/
     86            /*  Calculate Sample Mean with no mask                           */
     87            /*************************************************************************/
     88            printPositiveTestHeader( stdout,
     89                                     "psImageStats functions",
     90                                     "Calculate Sample Mean, no mask %d" );
     91                                     
     92            myStats = psImageStats( myStats, tmpImage, NULL, 0 );
     93            printf( "The sample mean was %.2f\n", myStats->sampleMean );
     94           
     95            psMemCheckCorruption( 1 );
     96           
     97            printFooter( stdout,
     98                         "psImageStats functions",
     99                         "Calculate Sample Mean, no mask",
     100                         testStatus );
     101                         
     102            /*************************************************************************/
     103            /*  Calculate Sample Mean with mask                              */
     104            /*************************************************************************/
     105            printPositiveTestHeader( stdout,
     106                                     "psImageStats functions",
     107                                     "Calculate Sample Mean with mask" );
     108                                     
     109            myStats = psImageStats( myStats, tmpImage, tmpMask, 1 );
     110            printf( "The sample mean was %.2f\n", myStats->sampleMean );
     111           
     112            psMemCheckCorruption( 1 );
     113           
     114            printFooter( stdout,
     115                         "psImageStats functions",
     116                         "Calculate Sample Mean with mask",
     117                         testStatus );
     118                         
     119            /*************************************************************************/
     120            /*  Deallocate data structures                                   */
     121            /*************************************************************************/
     122            printPositiveTestHeader( stdout,
     123                                     "psImageStats functions",
     124                                     "Deallocate the psStats/psImage structure." );
     125            psFree( myStats );
     126            psFree( tmpImage );
     127            psFree( tmpMask );
     128           
     129            psMemCheckCorruption( 1 );
     130            memLeaks = psMemCheckLeaks( currentId, NULL, NULL );
     131            if ( 0 != memLeaks ) {
     132                    psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks );
     133                }
     134               
     135            printFooter( stdout,
     136                         "psImageStats functions",
     137                         "Deallocate the psStats/psImage structure.",
     138                         testStatus );
    37139        }
    38         if (nb == 1) {
    39             IMAGE_X_SIZE = 1;
    40             IMAGE_Y_SIZE = N;
    41         }
    42         if (nb == 2) {
    43             IMAGE_X_SIZE = N;
    44             IMAGE_Y_SIZE = 1;
    45         }
    46         if (nb == 3) {
    47             IMAGE_X_SIZE = N;
    48             IMAGE_Y_SIZE = N;
    49         }
    50         if (nb == 4) {
    51             IMAGE_X_SIZE = N;
    52             IMAGE_Y_SIZE = M;
    53         }
    54         if (nb == 5) {
    55             IMAGE_X_SIZE = M;
    56             IMAGE_Y_SIZE = N;
    57         }
    58         printf("*******************************\n");
    59         printf("* IMAGE SIZE is (%d by %d)\n", IMAGE_X_SIZE, IMAGE_Y_SIZE);
    60         printf("*******************************\n");
    61 
    62         /*************************************************************************/
    63         /*  Allocate and initialize data structures                      */
    64         /*************************************************************************/
    65         tmpImage = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32);
    66 
    67         for (i=0;i<tmpImage->numRows;i++) {
    68             for (j=0;j<tmpImage->numCols;j++) {
    69                 tmpImage->data.F32[i][j] = (float) (i + j);
    70             }
    71         }
    72         tmpMask = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8);
    73         for (i=0;i<tmpMask->numRows;i++) {
    74             for (j=0;j<tmpMask->numCols;j++) {
    75                 if ((i > (tmpMask->numRows/2)) &&
    76                         (j > (tmpMask->numCols/2))) {
    77                     tmpMask->data.U8[i][j] = 1;
    78                 } else {
    79                     tmpMask->data.U8[i][j] = 0;
    80                 }
    81             }
    82         }
    83 
    84         myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    85         /*************************************************************************/
    86         /*  Calculate Sample Mean with no mask                           */
    87         /*************************************************************************/
    88         printPositiveTestHeader(stdout,
    89                                 "psImageStats functions",
    90                                 "Calculate Sample Mean, no mask %d");
    91 
    92         myStats = psImageStats(myStats, tmpImage, NULL, 0);
    93         printf("The sample mean was %f\n", myStats->sampleMean);
    94 
    95         psMemCheckCorruption(1);
    96 
    97         printFooter(stdout,
    98                     "psImageStats functions",
    99                     "Calculate Sample Mean, no mask",
    100                     testStatus);
    101 
    102         /*************************************************************************/
    103         /*  Calculate Sample Mean with mask                              */
    104         /*************************************************************************/
    105         printPositiveTestHeader(stdout,
    106                                 "psImageStats functions",
    107                                 "Calculate Sample Mean with mask");
    108 
    109         myStats = psImageStats(myStats, tmpImage, tmpMask, 1);
    110         printf("The sample mean was %f\n", myStats->sampleMean);
    111 
    112         psMemCheckCorruption(1);
    113 
    114         printFooter(stdout,
    115                     "psImageStats functions",
    116                     "Calculate Sample Mean with mask",
    117                     testStatus);
    118 
    119         /*************************************************************************/
    120         /*  Deallocate data structures                                   */
    121         /*************************************************************************/
    122         printPositiveTestHeader(stdout,
    123                                 "psImageStats functions",
    124                                 "Deallocate the psStats/psImage structure.");
    125         psFree(myStats);
    126         psFree(tmpImage);
    127         psFree(tmpMask);
    128 
    129         psMemCheckCorruption(1);
    130         memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
    131         if (0 != memLeaks) {
    132             psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    133         }
    134 
    135         printFooter(stdout,
    136                     "psImageStats functions",
    137                     "Deallocate the psStats/psImage structure.",
    138                     testStatus);
    139     }
    140 
     140       
    141141    /*************************************************************************/
    142142    /*  Test With Various Null Inputs                                        */
    143143    /*************************************************************************/
    144     printPositiveTestHeader(stdout,
    145                             "psImageStats functions",
    146                             "Test With Various Null Inputs");
    147 
    148     tmpImage = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32);
    149     tmpMask = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8);
    150     myStats = psStatsAlloc(0);
    151 
    152     myStats2 = psImageStats(myStats, NULL, NULL, 0);
    153     if (myStats2 != NULL) {
    154         printf("ERROR: myStats2 = psImageStats(myStats, NULL, NULL, 0) != NULL\n");
    155     }
    156 
    157     myStats2 = psImageStats(NULL, tmpImage, NULL, 0);
    158     if (myStats2 != NULL) {
    159         printf("ERROR: myStats2 = psImageStats(NULL, tmpImage, NULL, 0) != NULL\n");
    160     }
    161 
    162     myStats2 = psImageStats(myStats, tmpImage, NULL, 0);
    163 
    164     psFree(myStats);
    165     psFree(tmpImage);
    166     psFree(tmpMask);
    167 
    168     psMemCheckCorruption(1);
    169     memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
    170     if (0 != memLeaks) {
    171         psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    172     }
    173 
    174     printFooter(stdout,
    175                 "psImageStats functions",
    176                 "Test With Various Null Inputs",
    177                 testStatus);
    178     return (!testStatus);
     144    printPositiveTestHeader( stdout,
     145                             "psImageStats functions",
     146                             "Test With Various Null Inputs" );
     147                             
     148    tmpImage = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32 );
     149    tmpMask = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8 );
     150    myStats = psStatsAlloc( 0 );
     151   
     152    myStats2 = psImageStats( myStats, NULL, NULL, 0 );
     153    if ( myStats2 != NULL ) {
     154            printf( "ERROR: myStats2 = psImageStats(myStats, NULL, NULL, 0) != NULL\n" );
     155        }
     156       
     157    myStats2 = psImageStats( NULL, tmpImage, NULL, 0 );
     158    if ( myStats2 != NULL ) {
     159            printf( "ERROR: myStats2 = psImageStats(NULL, tmpImage, NULL, 0) != NULL\n" );
     160        }
     161       
     162    myStats2 = psImageStats( myStats, tmpImage, NULL, 0 );
     163   
     164    psFree( myStats );
     165    psFree( tmpImage );
     166    psFree( tmpMask );
     167   
     168    psMemCheckCorruption( 1 );
     169    memLeaks = psMemCheckLeaks( currentId, NULL, NULL );
     170    if ( 0 != memLeaks ) {
     171            psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks );
     172        }
     173       
     174    printFooter( stdout,
     175                 "psImageStats functions",
     176                 "Test With Various Null Inputs",
     177                 testStatus );
     178    return ( !testStatus );
    179179}
Note: See TracChangeset for help on using the changeset viewer.