Changeset 894 for trunk/psLib/test/image/tst_psImageStats01.c
- Timestamp:
- Jun 6, 2004, 5:43:22 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageStats01.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageStats01.c
r887 r894 12 12 #include "psImageStats.h" 13 13 #define NUM_BINS 20 14 #define IMAGE_SIZE 512 14 #define N 32 15 #define M 64 15 16 16 17 int main() 17 18 { 18 19 psStats *myStats = NULL; 20 psStats *myStats2 = NULL; 19 21 psImage *tmpImage = NULL; 20 22 psImage *tmpMask = NULL; 21 23 int testStatus = true; 22 24 int memLeaks = 0; 25 int nb = 0; 23 26 int i = 0; 24 27 int j = 0; 28 int IMAGE_X_SIZE = 0; 29 int IMAGE_Y_SIZE = 0; 25 30 int currentId = 0; 26 31 27 32 currentId = psMemGetId(); 28 /*************************************************************************/ 29 /* Allocate and initialize data structures */ 30 /*************************************************************************/ 31 tmpImage = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32); 32 for (i=0;i<IMAGE_SIZE;i++) { 33 for (j=0;j<IMAGE_SIZE;j++) { 34 tmpImage->data.F32[i][j] = (float) (i + j); 33 for (nb=0;nb<6;nb++) { 34 if (nb == 0) { 35 IMAGE_X_SIZE = 1; 36 IMAGE_Y_SIZE = 1; 35 37 } 36 } 37 tmpMask = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_U8); 38 for (i=0;i<IMAGE_SIZE;i++) { 39 for (j=0;j<IMAGE_SIZE;j++) { 40 if ((i > (IMAGE_SIZE/2)) && 41 (j > (IMAGE_SIZE/2))) { 42 tmpMask->data.U8[i][j] = 1; 43 } else { 44 tmpMask->data.U8[i][j] = 0; 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); 45 70 } 46 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 psStatsFree(myStats); 126 psImageFree(tmpImage); 127 psImageFree(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); 47 139 } 48 140 49 myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);50 141 /*************************************************************************/ 51 /* Calculate Sample Mean with no mask*/142 /* Test With Various Null Inputs */ 52 143 /*************************************************************************/ 53 144 printPositiveTestHeader(stdout, 54 145 "psImageStats functions", 55 "Calculate Sample Mean, no mask"); 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 } 56 161 57 162 myStats = psImageStats(myStats, tmpImage, NULL, 0); 58 printf("The sample mean was %f\n", myStats->sampleMean); 163 // 164 // NOTE: verify that myStats is good here. 165 // 59 166 60 psMemCheckCorruption(1);61 62 printFooter(stdout,63 "psImageStats functions",64 "Calculate Sample Mean, no mask",65 testStatus);66 67 /*************************************************************************/68 /* Calculate Sample Mean with mask */69 /*************************************************************************/70 printPositiveTestHeader(stdout,71 "psImageStats functions",72 "Calculate Sample Mean with mask");73 74 myStats = psImageStats(myStats, tmpImage, tmpMask, 1);75 printf("The sample mean was %f\n", myStats->sampleMean);76 77 psMemCheckCorruption(1);78 79 printFooter(stdout,80 "psImageStats functions",81 "Calculate Sample Mean with mask",82 testStatus);83 84 /*************************************************************************/85 /* Deallocate data structures */86 /*************************************************************************/87 printPositiveTestHeader(stdout,88 "psImageStats functions",89 "Deallocate the psStats/psImage structure.");90 167 psStatsFree(myStats); 91 168 psImageFree(tmpImage); … … 100 177 printFooter(stdout, 101 178 "psImageStats functions", 102 " Deallocate the psStats/psImage structure.",179 "Test With Various Null Inputs", 103 180 testStatus); 104 105 181 return (!testStatus); 106 182 }
Note:
See TracChangeset
for help on using the changeset viewer.
