Changeset 889 for trunk/psLib/src/image/psImageStats.c
- Timestamp:
- Jun 6, 2004, 2:32:53 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageStats.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageStats.c
r831 r889 19 19 20 20 /// This routine must determine the various statistics for the image. 21 /***************************************************************************** 22 GUS: verify that image/mask have the 23 correct types 24 sizes 25 *****************************************************************************/ 21 26 psStats *psImageStats(psStats *stats, 22 27 psImage *in, … … 26 31 psVector *junkData=NULL; 27 32 psVector *junkMask=NULL; 33 int ptr = 0; 34 int i = 0; 35 int j = 0; 28 36 29 37 junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type); 30 junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type); 31 32 // GUS: figure out mask types 33 junkData->data.F32 = (float *) in->data.F32; 34 junkMask->data.F32 = (float *) mask->data.F32; 35 stats = psVectorStats(stats, junkData, junkMask, maskVal); 38 junkData->n = junkData->nalloc; 39 ptr=0; 40 for (i=0;i<in->numRows;i++) { 41 for (j=0;j<in->numCols;j++) { 42 junkData->data.F32[ptr++] = in->data.F32[i][j]; 43 } 44 } 45 46 if (mask != NULL) { 47 // GUS: verify that mask data is PS_TYPE_U8. 48 // GUS: figure out mask types 49 50 junkMask = psVectorAlloc(mask->numRows * mask->numCols, 51 mask->type.type); 52 junkMask->n = junkMask->nalloc; 53 // GUS: Is there a more efficient way to do this? 54 ptr=0; 55 for (i=0;i<mask->numRows;i++) { 56 for (j=0;j<mask->numCols;j++) { 57 junkMask->data.U8[ptr++] = mask->data.U8[i][j]; 58 } 59 } 60 61 stats = psVectorStats(stats, junkData, junkMask, maskVal); 62 psVectorFree(junkMask); 63 } else { 64 stats = psVectorStats(stats, junkData, NULL, 0); 65 } 36 66 37 67 psVectorFree(junkData); 38 psVectorFree(junkMask);39 68 40 69 return(stats); … … 44 73 NOTE: We assume that the psHistogram structure out has already been 45 74 allocated and initialized. 75 76 GUS: verify that image/mask have the 77 correct types 78 sizes 46 79 *****************************************************************************/ 47 80 psHistogram *psImageHistogram(psHistogram *out, … … 52 85 psVector *junkData=NULL; 53 86 psVector *junkMask=NULL; 87 int ptr = 0; 88 int i = 0; 89 int j = 0; 54 90 55 91 junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type); 56 junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type); 57 58 // GUS: figure out mask types 59 junkData->data.F32 = (float *) in->data.F32; 60 junkMask->data.F32 = (float *) mask->data.F32; 61 62 out = psHistogramVector(out, junkData, junkMask, maskVal); 63 92 junkData->n = junkData->nalloc; 93 94 // GUS: Is there a more efficient way to do this? memcopy() won't work. 95 // Can we trick the junkData structure to use the image buffer, then 96 // untrick it before we deallocate it (so we won't deallocate that buffer 97 // twice? 98 99 // GUS: Make sure you have the numRows/NumCols in the right place. 100 ptr=0; 101 for (i=0;i<in->numRows;i++) { 102 for (j=0;j<in->numCols;j++) { 103 junkData->data.F32[ptr++] = in->data.F32[i][j]; 104 } 105 } 106 107 if (mask != NULL) { 108 // GUS: verify that mask data is PS_TYPE_U8. 109 // GUS: figure out mask types 110 111 junkMask = psVectorAlloc(mask->numRows * mask->numCols, 112 mask->type.type); 113 junkMask->n = junkMask->nalloc; 114 115 // GUS: Is there a more efficient way to do this? 116 ptr=0; 117 for (i=0;i<mask->numRows;i++) { 118 for (j=0;j<mask->numCols;j++) { 119 junkMask->data.U8[ptr++] = mask->data.U8[i][j]; 120 } 121 } 122 out = psHistogramVector(out, junkData, junkMask, maskVal); 123 psVectorFree(junkMask); 124 } else { 125 out = psHistogramVector(out, junkData, NULL, 0); 126 } 64 127 psVectorFree(junkData); 65 psVectorFree(junkMask);66 128 67 129 return(out); … … 91 153 int maxChebyPoly = 0; 92 154 155 93 156 // Create the sums[][] data structure. This will hold the LHS of equation 94 157 // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) } 158 95 159 sums = (float **) psAlloc(coeffs->nX * sizeof(float *)); 96 160 for (i=0;i<coeffs->nX;i++) { … … 105 169 // Determine how many Chebyshev polynomials are needed, then create them. 106 170 maxChebyPoly = coeffs->nX; 107 if (coeffs->n X > coeffs->nY) {171 if (coeffs->nY > coeffs->nX) { 108 172 maxChebyPoly = coeffs->nY; 109 173 } … … 133 197 psEvalPolynomial1D((float) x, chebPolys[i]) * 134 198 psEvalPolynomial1D((float) y, chebPolys[j]); 199 135 200 } 136 201 } … … 160 225 } 161 226 162 163 227 // Free the Chebyshev polynomials that were created in this routine. 164 228 for (i=0;i<maxChebyPoly;i++) { 165 psFree(chebPolys[i]); 166 } 229 psPolynomial1DFree(chebPolys[i]); 230 } 231 psFree(chebPolys); 232 233 // Free some data 234 for (i=0;i<coeffs->nX;i++) { 235 psFree(sums[i]); 236 } 237 psFree(sums); 167 238 168 239 return(coeffs); … … 199 270 // Determine how many Chebyshev polynomials are needed, then create them. 200 271 maxChebyPoly = coeffs->nX; 201 if (coeffs->n X > coeffs->nY) {272 if (coeffs->nY > coeffs->nX) { 202 273 maxChebyPoly = coeffs->nY; 203 274 } … … 219 290 } 220 291 } 221 222 292 223 293 for (x=0;x<input->numRows;x++) { … … 227 297 for (j=0;j<coeffs->nY;j++) { 228 298 polySum+= psEvalPolynomial1D((float)x, chebPolys[i]) * 229 psEvalPolynomial1D((float)y, chebPolys[ y]) *299 psEvalPolynomial1D((float)y, chebPolys[j]) * 230 300 coeffs->coeff[i][j]; 231 232 301 } 233 302 } … … 236 305 } 237 306 238 239 307 // Free the Chebyshev polynomials that were created in this routine. 240 308 for (i=0;i<maxChebyPoly;i++) { 241 psFree(chebPolys[i]); 242 } 309 psPolynomial1DFree(chebPolys[i]); 310 } 311 psFree(chebPolys); 312 313 // Free some data 314 for (i=0;i<coeffs->nX;i++) { 315 psFree(sums[i]); 316 } 317 psFree(sums); 243 318 244 319 return(0);
Note:
See TracChangeset
for help on using the changeset viewer.
