Changeset 904 for trunk/psLib/test/image/tst_psImageStats00.c
- Timestamp:
- Jun 7, 2004, 3:08:33 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageStats00.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageStats00.c
r887 r904 11 11 #define NUM_BINS 20 12 12 #define IMAGE_SIZE 20 13 #define N 32 14 #define M 64 13 15 14 16 int main() 15 17 { 16 18 psHistogram *myHist = NULL; 19 psHistogram *myHist2= NULL; 17 20 psImage *tmpImage = NULL; 18 21 psImage *tmpMask = NULL; 19 22 int testStatus = true; 20 23 int memLeaks = 0; 24 int nb = 0; 21 25 int i = 0; 22 26 int j = 0; 27 int IMAGE_X_SIZE = 0; 28 int IMAGE_Y_SIZE = 0; 23 29 int currentId = 0; 24 30 25 31 currentId = psMemGetId(); 26 /*************************************************************************/ 27 /* Allocate and initialize data structures */ 28 /*************************************************************************/ 29 tmpImage = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32); 30 for (i=0;i<IMAGE_SIZE;i++) { 31 for (j=0;j<IMAGE_SIZE;j++) { 32 tmpImage->data.F32[i][j] = (float) (i + j); 32 for (nb=0;nb<6;nb++) { 33 if (nb == 0) { 34 IMAGE_X_SIZE = 1; 35 IMAGE_Y_SIZE = 1; 33 36 } 34 } 35 tmpMask = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_U8); 36 for (i=0;i<IMAGE_SIZE;i++) { 37 for (j=0;j<IMAGE_SIZE;j++) { 38 if ((i > (IMAGE_SIZE/2)) && 39 (j > (IMAGE_SIZE/2))) { 40 tmpMask->data.U8[i][j] = 1; 41 } else { 42 tmpMask->data.U8[i][j] = 0; 37 if (nb == 1) { 38 IMAGE_X_SIZE = 1; 39 IMAGE_Y_SIZE = N; 40 } 41 if (nb == 2) { 42 IMAGE_X_SIZE = N; 43 IMAGE_Y_SIZE = 1; 44 } 45 if (nb == 3) { 46 IMAGE_X_SIZE = N; 47 IMAGE_Y_SIZE = N; 48 } 49 if (nb == 4) { 50 IMAGE_X_SIZE = N; 51 IMAGE_Y_SIZE = M; 52 } 53 if (nb == 5) { 54 IMAGE_X_SIZE = M; 55 IMAGE_Y_SIZE = N; 56 } 57 printf("*******************************\n"); 58 printf("* IMAGE SIZE is (%d by %d)\n", IMAGE_X_SIZE, IMAGE_Y_SIZE); 59 printf("*******************************\n"); 60 /*********************************************************************/ 61 /* Allocate and initialize data structures */ 62 /*********************************************************************/ 63 tmpImage = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32); 64 65 for (i=0;i<tmpImage->numRows;i++) { 66 for (j=0;j<tmpImage->numCols;j++) { 67 tmpImage->data.F32[i][j] = (float) (i + j); 43 68 } 44 69 } 70 tmpMask = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8); 71 for (i=0;i<tmpMask->numRows;i++) { 72 for (j=0;j<tmpMask->numCols;j++) { 73 if ((i > (tmpMask->numRows/2)) && 74 (j > (tmpMask->numCols/2))) { 75 tmpMask->data.U8[i][j] = 1; 76 } else { 77 tmpMask->data.U8[i][j] = 0; 78 } 79 } 80 } 81 82 /*************************************************************************/ 83 /* Calculate Histogram with no mask */ 84 /*************************************************************************/ 85 printPositiveTestHeader(stdout, 86 "psImageStats functions", 87 "Calculate Histogram, no mask"); 88 89 myHist = psHistogramAlloc(0.0, (float) (IMAGE_X_SIZE + IMAGE_Y_SIZE), 90 NUM_BINS); 91 myHist = psImageHistogram(myHist, tmpImage, NULL, 0); 92 for (i=0;i<NUM_BINS;i++) { 93 printf("Bin number %d bounds: (%f - %f) data (%d)\n", i, 94 myHist->bounds->data.F32[i], 95 myHist->bounds->data.F32[i+1], 96 myHist->nums->data.S32[i]); 97 } 98 psHistogramFree(myHist); 99 100 psMemCheckCorruption(1); 101 printFooter(stdout, 102 "psImageStats functions", 103 "Calculate Histogram, no mask", 104 testStatus); 105 106 /*************************************************************************/ 107 /* Calculate Histogram with mask */ 108 /*************************************************************************/ 109 printPositiveTestHeader(stdout, 110 "psImageStats functions", 111 "Calculate Histogram with mask"); 112 113 myHist = psHistogramAlloc(0.0, (float) (IMAGE_X_SIZE + IMAGE_Y_SIZE), 114 NUM_BINS); 115 myHist = psImageHistogram(myHist, tmpImage, tmpMask, 1); 116 for (i=0;i<NUM_BINS;i++) { 117 printf("Bin number %d bounds: (%f - %f) data (%d)\n", i, 118 myHist->bounds->data.F32[i], 119 myHist->bounds->data.F32[i+1], 120 myHist->nums->data.S32[i]); 121 } 122 123 psMemCheckCorruption(1); 124 printFooter(stdout, 125 "psImageStats functions", 126 "Calculate Histogram with mask", 127 testStatus); 128 129 /*************************************************************************/ 130 /* Deallocate data structures */ 131 /*************************************************************************/ 132 printPositiveTestHeader(stdout, 133 "psImageStats functions", 134 "Deallocate the psHistogram/psImage structure."); 135 psHistogramFree(myHist); 136 psImageFree(tmpImage); 137 psImageFree(tmpMask); 138 139 psMemCheckCorruption(1); 140 memLeaks = psMemCheckLeaks(currentId,NULL,NULL); 141 if (0 != memLeaks) { 142 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 143 } 144 145 printFooter(stdout, 146 "psImageStats functions", 147 "Deallocate the psHistogram/psImage structure.", 148 testStatus); 45 149 } 46 /*************************************************************************/47 /* Calculate Histogram with no mask */48 /*************************************************************************/49 150 printPositiveTestHeader(stdout, 50 151 "psImageStats functions", 51 "Cal culate Histogram, no mask");152 "Calling psImageHistogram() with NULL parameters"); 52 153 53 myHist = psHistogramAlloc(0.0, (float) (2 * IMAGE_SIZE), NUM_BINS); 54 myHist = psImageHistogram(myHist, tmpImage, NULL, 0); 55 for (i=0;i<NUM_BINS;i++) { 56 printf("Bin number %d bounds: (%f - %f) data (%d)\n", i, 57 myHist->bounds->data.F32[i], 58 myHist->bounds->data.F32[i+1], 59 myHist->nums->data.S32[i]); 154 tmpImage = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32); 155 myHist = psHistogramAlloc(0.0, (float) (IMAGE_X_SIZE + IMAGE_Y_SIZE), 156 NUM_BINS); 157 myHist2 = psImageHistogram(NULL, tmpImage, NULL, 0); 158 if (myHist2 != NULL) { 159 printf("ERROR: myHist2 not equal to NULL\n"); 60 160 } 61 psHistogramFree(myHist);62 161 63 psMemCheckCorruption(1); 64 printFooter(stdout, 65 "psImageStats functions", 66 "Calculate Histogram, no mask", 67 testStatus); 68 69 /*************************************************************************/ 70 /* Calculate Histogram with mask */ 71 /*************************************************************************/ 72 printPositiveTestHeader(stdout, 73 "psImageStats functions", 74 "Calculate Histogram with mask"); 75 76 myHist = psHistogramAlloc(0.0, (float) (2 * IMAGE_SIZE), NUM_BINS); 77 myHist = psImageHistogram(myHist, tmpImage, tmpMask, 1); 78 for (i=0;i<NUM_BINS;i++) { 79 printf("Bin number %d bounds: (%f - %f) data (%d)\n", i, 80 myHist->bounds->data.F32[i], 81 myHist->bounds->data.F32[i+1], 82 myHist->nums->data.S32[i]); 162 myHist2 = psImageHistogram(myHist, NULL, NULL, 0); 163 myHist2 = psImageHistogram(NULL, tmpImage, NULL, 0); 164 if (myHist2 != NULL) { 165 printf("ERROR: myHist2 not equal to NULL\n"); 83 166 } 84 167 85 168 psMemCheckCorruption(1); 86 printFooter(stdout,87 "psImageStats functions",88 "Calculate Histogram with mask",89 testStatus);90 91 /*************************************************************************/92 /* Deallocate data structures */93 /*************************************************************************/94 printPositiveTestHeader(stdout,95 "psImageStats functions",96 "Deallocate the psHistogram/psImage structure.");97 169 psHistogramFree(myHist); 98 170 psImageFree(tmpImage); 99 psImageFree(tmpMask);100 101 171 psMemCheckCorruption(1); 102 172 memLeaks = psMemCheckLeaks(currentId,NULL,NULL); … … 107 177 printFooter(stdout, 108 178 "psImageStats functions", 109 " Deallocate the psHistogram/psImage structure.",179 "Calling psImageHistogram() with NULL parameters", 110 180 testStatus); 111 181
Note:
See TracChangeset
for help on using the changeset viewer.
