Changeset 18901
- Timestamp:
- Aug 4, 2008, 4:08:44 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmFootprintFind.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmFootprintFind.c
r18844 r18901 4 4 * @author RHL, Princeton & IfA; EAM, IfA 5 5 * 6 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $7 * @date $Date: 2008-08-0 1 18:32:27$6 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2008-08-05 02:08:44 $ 8 8 * Copyright 2006 Institute for Astronomy, University of Hawaii 9 9 */ … … 82 82 assert(img != NULL); 83 83 84 bool F32 = false; // is this an F32 image? 85 if (img->type.type == PS_TYPE_F32) { 86 F32 = true; 87 } else if (img->type.type == PS_TYPE_S32) { 88 F32 = false; 89 } else { // N.b. You can't trivially add more cases here; F32 is just a bool 90 psError(PS_ERR_UNKNOWN, true, "Unsupported psImage type: %d", img->type.type); 91 return NULL; 92 } 93 psF32 *imgRowF32 = NULL; // row pointer if F32 94 psS32 *imgRowS32 = NULL; // " " " " !F32 84 psImage *floatImg = img->type.type == PS_TYPE_F32 ? psMemIncrRefCounter(img) : 85 psImageCopy(NULL, img, PS_TYPE_F32); // Floating-point version of image 95 86 96 87 const int row0 = img->row0; … … 116 107 */ 117 108 for (int i = 0; i < numRows; i++) { 118 int j; 119 tmp = idc; idc = idp; idp = tmp; /* swap ID pointers */ 120 memset(idc, '\0', numCols*sizeof(int)); 121 122 imgRowF32 = img->data.F32[i]; // only one of 123 imgRowS32 = img->data.S32[i]; // these is valid! 124 125 in_span = 0; /* not in a span */ 126 for (j = 0; j < numCols; j++) { 127 double pixVal = F32 ? imgRowF32[j] : imgRowS32[j]; 128 if (pixVal < threshold) { 129 if (in_span) { 130 if(nspan >= size_spans) { 131 size_spans *= 2; 132 spans = psRealloc(spans, size_spans*sizeof(WSPAN)); 133 } 134 spans[nspan].id = in_span; 135 spans[nspan].y = i; 136 spans[nspan].x0 = x0; 137 spans[nspan].x1 = j - 1; 138 139 nspan++; 140 141 in_span = 0; 142 } 143 } else { /* a pixel to fix */ 144 if(idc[j - 1] != 0) { 145 id = idc[j - 1]; 146 } else if(idp[j - 1] != 0) { 147 id = idp[j - 1]; 148 } else if(idp[j] != 0) { 149 id = idp[j]; 150 } else if(idp[j + 1] != 0) { 151 id = idp[j + 1]; 152 } else { 153 id = ++nobj; 154 155 if(id >= size_aliases) { 156 size_aliases *= 2; 157 aliases = psRealloc(aliases, size_aliases*sizeof(int)); 158 } 159 aliases[id] = id; 160 } 161 162 idc[j] = id; 163 if(!in_span) { 164 x0 = j; in_span = id; 165 } 166 /* 167 * Do we need to merge ID numbers? If so, make suitable entries in aliases[] 168 */ 169 if(idp[j + 1] != 0 && idp[j + 1] != id) { 170 aliases[resolve_alias(aliases, idp[j + 1])] = 171 resolve_alias(aliases, id); 172 173 idc[j] = id = idp[j + 1]; 174 } 175 } 176 } 177 178 if(in_span) { 179 if(nspan >= size_spans) { 180 size_spans *= 2; 181 spans = psRealloc(spans, size_spans*sizeof(WSPAN)); 182 } 183 184 assert(nspan < size_spans); /* we checked for space above */ 185 spans[nspan].id = in_span; 186 spans[nspan].y = i; 187 spans[nspan].x0 = x0; 188 spans[nspan].x1 = j - 1; 189 190 nspan++; 191 } 192 } 109 tmp = idc; idc = idp; idp = tmp; /* swap ID pointers */ 110 memset(idc, '\0', numCols*sizeof(int)); 111 112 in_span = 0; /* not in a span */ 113 for (int j = 0; j < numCols; j++) { 114 double pixVal = floatImg->data.F32[i][j]; // Value of pixel 115 if (pixVal < threshold) { 116 if (in_span) { 117 if(nspan >= size_spans) { 118 size_spans *= 2; 119 spans = psRealloc(spans, size_spans*sizeof(WSPAN)); 120 } 121 spans[nspan].id = in_span; 122 spans[nspan].y = i; 123 spans[nspan].x0 = x0; 124 spans[nspan].x1 = j - 1; 125 126 nspan++; 127 128 in_span = 0; 129 } 130 } else { /* a pixel to fix */ 131 if(idc[j - 1] != 0) { 132 id = idc[j - 1]; 133 } else if(idp[j - 1] != 0) { 134 id = idp[j - 1]; 135 } else if(idp[j] != 0) { 136 id = idp[j]; 137 } else if(idp[j + 1] != 0) { 138 id = idp[j + 1]; 139 } else { 140 id = ++nobj; 141 142 if(id >= size_aliases) { 143 size_aliases *= 2; 144 aliases = psRealloc(aliases, size_aliases*sizeof(int)); 145 } 146 aliases[id] = id; 147 } 148 149 idc[j] = id; 150 if(!in_span) { 151 x0 = j; in_span = id; 152 } 153 /* 154 * Do we need to merge ID numbers? If so, make suitable entries in aliases[] 155 */ 156 if(idp[j + 1] != 0 && idp[j + 1] != id) { 157 aliases[resolve_alias(aliases, idp[j + 1])] = 158 resolve_alias(aliases, id); 159 160 idc[j] = id = idp[j + 1]; 161 } 162 } 163 } 164 165 if(in_span) { 166 if(nspan >= size_spans) { 167 size_spans *= 2; 168 spans = psRealloc(spans, size_spans*sizeof(WSPAN)); 169 } 170 171 assert(nspan < size_spans); /* we checked for space above */ 172 spans[nspan].id = in_span; 173 spans[nspan].y = i; 174 spans[nspan].x0 = x0; 175 spans[nspan].x1 = j - 1; 176 177 nspan++; 178 } 179 } 180 psFree(floatImg); 193 181 194 182 psFree(id_s); 195 /*196 * Resolve aliases; first alias chains, then the IDs in the spans197 */183 /* 184 * Resolve aliases; first alias chains, then the IDs in the spans 185 */ 198 186 for (int i = 0; i < nspan; i++) { 199 spans[i].id = resolve_alias(aliases, spans[i].id);187 spans[i].id = resolve_alias(aliases, spans[i].id); 200 188 } 201 189 202 190 psFree(aliases); 203 /*204 * Sort spans by ID, so we can sweep through them once205 * XXX replace with a psLib sort call206 */191 /* 192 * Sort spans by ID, so we can sweep through them once 193 * XXX replace with a psLib sort call 194 */ 207 195 if(nspan > 0) { 208 qsort(spans, nspan, sizeof(WSPAN), compar);209 } 210 /*211 * Build pmFootprints from the spans212 */196 qsort(spans, nspan, sizeof(WSPAN), compar); 197 } 198 /* 199 * Build pmFootprints from the spans 200 */ 213 201 psArray *footprints = psArrayAlloc(nobj); 214 202 int n = 0; // number of pmFootprints 215 203 216 204 if(nspan > 0) { 217 id = spans[0].id;218 i0 = 0;219 for (int i = 0; i <= nspan; i++) { /* nspan + 1 to catch last object */220 if(i == nspan || spans[i].id != id) {221 pmFootprint *fp = pmFootprintAlloc(i - i0, img);222 223 for(; i0 < i; i0++) {224 pmFootprintAddSpan(fp, spans[i0].y + row0,225 spans[i0].x0 + col0, spans[i0].x1 + col0);226 }227 228 if (fp->npix < npixMin) {229 psFree(fp);230 } else {231 footprints->data[n++] = fp;232 }233 }234 235 id = spans[i].id;236 }205 id = spans[0].id; 206 i0 = 0; 207 for (int i = 0; i <= nspan; i++) { /* nspan + 1 to catch last object */ 208 if(i == nspan || spans[i].id != id) { 209 pmFootprint *fp = pmFootprintAlloc(i - i0, img); 210 211 for(; i0 < i; i0++) { 212 pmFootprintAddSpan(fp, spans[i0].y + row0, 213 spans[i0].x0 + col0, spans[i0].x1 + col0); 214 } 215 216 if (fp->npix < npixMin) { 217 psFree(fp); 218 } else { 219 footprints->data[n++] = fp; 220 } 221 } 222 223 id = spans[i].id; 224 } 237 225 } 238 226 239 227 footprints = psArrayRealloc(footprints, n); 240 /*241 * clean up242 */228 /* 229 * clean up 230 */ 243 231 psFree(spans); 244 232
Note:
See TracChangeset
for help on using the changeset viewer.
