Changeset 1234 for trunk/psLib/src/imageops/psImageStats.c
- Timestamp:
- Jul 15, 2004, 2:42:00 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageStats.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageStats.c
r1233 r1234 25 25 int maskVal) 26 26 { 27 psVector *junkData=NULL; 28 psVector *junkMask=NULL; 29 int ptr = 0; 30 int i = 0; 31 int j = 0; 32 33 // NOTE: Verify this action. 34 if ((stats == NULL) || 35 (in == NULL)) { 36 return(NULL); 37 } 38 // NOTE: Verify this action. 27 psVector* junkData=NULL; 28 psVector* junkMask=NULL; 29 30 if (stats == NULL) { 31 psError(__func__,"The input psStats struct can not be NULL."); 32 return NULL; 33 } 34 35 if (in == NULL) { 36 psError(__func__,"The input image can not be NULL."); 37 return NULL; 38 } 39 39 40 if (stats->options == 0) { 40 return(stats); 41 } 42 43 junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type); 41 psError(__func__,"No statistic option/operation was specified."); 42 return stats; 43 } 44 45 // stuff the image data into a psVector struct. 46 junkData = psAlloc(sizeof(psVector)); 47 junkData->type = in->type; 48 junkData->nalloc = in->numRows*in->numCols; 44 49 junkData->n = junkData->nalloc; 45 ptr=0; 46 for (i=0;i<in->numRows;i++) { 47 for (j=0;j<in->numCols;j++) { 48 junkData->data.F32[ptr++] = in->data.F32[i][j]; 49 } 50 } 50 junkData->data.V = in->data.V[0]; // since psImage data is contiguous... 51 51 52 52 if (mask != NULL) { 53 // NOTE: verify that mask data is PS_TYPE_U8. 54 // NOTE: figure out mask types 55 56 junkMask = psVectorAlloc(mask->numRows * mask->numCols, 57 mask->type.type); 53 if (mask->type.type != PS_TYPE_MASK) { 54 psError(__func__, "Expected the mask image type not found (type=%x)", 55 mask->type.type); 56 psFree(junkData); 57 return NULL; 58 } 59 60 // stuff the mask data into a psVector struct. 61 junkMask = psAlloc(sizeof(psVector)); 62 junkMask->type = mask->type; 63 junkMask->nalloc = mask->numRows*mask->numCols; 58 64 junkMask->n = junkMask->nalloc; 59 // NOTE: Is there a more efficient way to do this? 60 ptr=0; 61 for (i=0;i<mask->numRows;i++) { 62 for (j=0;j<mask->numCols;j++) { 63 junkMask->data.U8[ptr++] = mask->data.U8[i][j]; 64 } 65 } 66 67 stats = psVectorStats(stats, junkData, junkMask, maskVal); 68 psFree(junkMask); 69 } else { 70 stats = psVectorStats(stats, junkData, NULL, 0); 71 } 65 junkMask->data.V = mask->data.V[0]; 66 } 67 68 stats = psVectorStats(stats, junkData, junkMask, maskVal); 69 70 psFree(junkMask); 72 71 psFree(junkData); 73 72 return(stats); … … 86 85 psVector *junkData=NULL; 87 86 psVector *junkMask=NULL; 88 int ptr = 0;89 int i = 0;90 int j = 0;91 87 92 88 // NOTE: Verify this action. … … 96 92 } 97 93 98 junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type); 94 junkData = psAlloc(sizeof(psVector)); 95 junkData->type = in->type; 96 junkData->nalloc = in->numRows*in->numCols; 99 97 junkData->n = junkData->nalloc; 100 101 // NOTE: Is there a more efficient way to do this? memcopy() won't work. 102 // Can we trick the junkData structure to use the image buffer, then 103 // untrick it before we deallocate it (so we won't deallocate that buffer 104 // twice? 105 106 // NOTE: Make sure you have the numRows/NumCols in the right place. 107 ptr=0; 108 for (i=0;i<in->numRows;i++) { 109 for (j=0;j<in->numCols;j++) { 110 junkData->data.F32[ptr++] = in->data.F32[i][j]; 111 } 112 } 98 junkData->data.V = in->data.V[0]; // since psImage data is contiguous... 113 99 114 100 if (mask != NULL) { 115 // NOTE: verify that mask data is PS_TYPE_U8. 116 // NOTE: figure out mask types 117 118 junkMask = psVectorAlloc(mask->numRows * mask->numCols, 119 mask->type.type); 101 if (mask->type.type != PS_TYPE_MASK) { 102 psError(__func__, "Expected the mask image type not found (type=%x)", 103 mask->type.type); 104 psFree(junkData); 105 return NULL; 106 } 107 108 // stuff the mask data into a psVector struct. 109 junkMask = psAlloc(sizeof(psVector)); 110 junkMask->type = mask->type; 111 junkMask->nalloc = mask->numRows*mask->numCols; 120 112 junkMask->n = junkMask->nalloc; 121 122 // NOTE: Is there a more efficient way to do this? 123 ptr=0; 124 for (i=0;i<mask->numRows;i++) { 125 for (j=0;j<mask->numCols;j++) { 126 junkMask->data.U8[ptr++] = mask->data.U8[i][j]; 127 } 128 } 129 out = psHistogramVector(out, junkData, junkMask, maskVal); 130 psFree(junkMask); 131 } else { 132 out = psHistogramVector(out, junkData, NULL, 0); 133 } 113 junkMask->data.V = mask->data.V[0]; 114 } 115 116 out = psHistogramVector(out, junkData, junkMask, maskVal); 117 118 psFree(junkMask); 134 119 psFree(junkData); 135 120
Note:
See TracChangeset
for help on using the changeset viewer.
