Changeset 20938 for trunk/psphot/src/psphotSourceSize.c
- Timestamp:
- Dec 7, 2008, 4:52:04 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceSize.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceSize.c
r20878 r20938 4 4 static float psphotModelContour(const psImage *image, const psImage *weight, const psImage *mask, 5 5 psMaskType maskVal, const pmModel *model, float Ro); 6 7 bool psphotMaskCosmicRay_Old (pmSource *source, psMaskType maskVal, psMaskType crMask); 8 bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psMaskType maskVal, psMaskType crMask); 6 9 7 10 // we need to call this function after sources have been fitted to the PSF model and … … 157 160 // this source is thought to be a cosmic ray. flag the detection and mask the pixels 158 161 if (source->crNsigma > CR_NSIGMA_LIMIT) { 159 source->mode |= PM_SOURCE_MODE_CR_LIMIT; 160 pmPeak *peak = source->peak; 161 psAssert (peak, "NULL peak"); 162 163 // replace the source flux 164 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 165 source->mode &= ~PM_SOURCE_MODE_SUBTRACTED; 166 167 psImage *mask = source->maskView; 168 psImage *pixels = source->pixels; 169 psImage *weight = source->weight; 170 171 // XXX This should be a recipe variable 172 # define SN_LIMIT 5.0 173 174 int xo = peak->x - pixels->col0; 175 int yo = peak->y - pixels->row0; 176 177 // mark the pixels in this row to the left, then the right 178 for (int ix = xo; ix >= 0; ix--) { 179 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]); 180 if (SN > SN_LIMIT) { 181 mask->data.U8[yo][ix] |= crMask; 182 } 183 } 184 for (int ix = xo + 1; ix < pixels->numCols; ix++) { 185 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]); 186 if (SN > SN_LIMIT) { 187 mask->data.U8[yo][ix] |= crMask; 188 } 189 } 190 191 // for each of the neighboring rows, mark the high pixels if they have a marked neighbor 192 // first go up: 193 for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) { 194 // mark the pixels in this row to the left, then the right 195 for (int ix = 0; ix < pixels->numCols; ix++) { 196 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 197 if (SN < SN_LIMIT) continue; 198 199 bool valid = false; 200 valid |= (mask->data.U8[iy+1][ix] & crMask); 201 valid |= (ix > 0) ? (mask->data.U8[iy+1][ix-1] & crMask) : 0; 202 valid |= (ix <= mask->numCols) ? (mask->data.U8[iy+1][ix+1] & crMask) : 0; 203 204 if (!valid) continue; 205 mask->data.U8[iy][ix] |= crMask; 206 } 207 } 208 // next go down: 209 for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) { 210 // mark the pixels in this row to the left, then the right 211 for (int ix = 0; ix < pixels->numCols; ix++) { 212 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 213 if (SN < SN_LIMIT) continue; 214 215 bool valid = false; 216 valid |= (mask->data.U8[iy-1][ix] & crMask); 217 valid |= (ix > 0) ? (mask->data.U8[iy-1][ix-1] & crMask) : 0; 218 valid |= (ix <= mask->numCols) ? (mask->data.U8[iy-1][ix+1] & crMask) : 0; 219 220 if (!valid) continue; 221 mask->data.U8[iy][ix] |= crMask; 222 } 223 } 162 // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask); 163 psphotMaskCosmicRay_Old (source, maskVal, crMask); 224 164 } 225 165 } … … 242 182 243 183 psphotVisualPlotSourceSize (sources); 244 psphotVisualShowSourceSize ( sources);184 psphotVisualShowSourceSize (readout, sources); 245 185 246 186 return true; … … 319 259 return nSigma; 320 260 } 261 262 bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psMaskType maskVal, psMaskType crMask) { 263 264 // replace the source flux 265 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 266 source->mode &= ~PM_SOURCE_MODE_SUBTRACTED; 267 268 // flag this as a CR 269 source->mode |= PM_SOURCE_MODE_CR_LIMIT; 270 pmPeak *peak = source->peak; 271 psAssert (peak, "NULL peak"); 272 273 // grab the matching footprint 274 pmFootprint *footprint = peak->footprint; 275 if (!footprint) { 276 // if we have not footprint, use the old code to mask by isophot 277 psphotMaskCosmicRay_Old (source, maskVal, crMask); 278 return true; 279 } 280 281 if (!footprint->spans) { 282 // if we have not footprint, use the old code to mask by isophot 283 psphotMaskCosmicRay_Old (source, maskVal, crMask); 284 return true; 285 } 286 287 // mask all of the pixels covered by the spans of the footprint 288 for (int j = 1; j < footprint->spans->n; j++) { 289 pmSpan *span1 = footprint->spans->data[j]; 290 291 int iy = span1->y; 292 int xs = span1->x0; 293 int xe = span1->x1; 294 295 for (int ix = xs; ix < xe; ix++) { 296 mask->data.U8[iy][ix] |= crMask; 297 } 298 } 299 return true; 300 } 301 302 bool psphotMaskCosmicRay_Old (pmSource *source, psMaskType maskVal, psMaskType crMask) { 303 304 source->mode |= PM_SOURCE_MODE_CR_LIMIT; 305 pmPeak *peak = source->peak; 306 psAssert (peak, "NULL peak"); 307 308 psImage *mask = source->maskView; 309 psImage *pixels = source->pixels; 310 psImage *weight = source->weight; 311 312 // XXX This should be a recipe variable 313 # define SN_LIMIT 5.0 314 315 int xo = peak->x - pixels->col0; 316 int yo = peak->y - pixels->row0; 317 318 // mark the pixels in this row to the left, then the right 319 for (int ix = xo; ix >= 0; ix--) { 320 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]); 321 if (SN > SN_LIMIT) { 322 mask->data.U8[yo][ix] |= crMask; 323 } 324 } 325 for (int ix = xo + 1; ix < pixels->numCols; ix++) { 326 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]); 327 if (SN > SN_LIMIT) { 328 mask->data.U8[yo][ix] |= crMask; 329 } 330 } 331 332 // for each of the neighboring rows, mark the high pixels if they have a marked neighbor 333 // first go up: 334 for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) { 335 // mark the pixels in this row to the left, then the right 336 for (int ix = 0; ix < pixels->numCols; ix++) { 337 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 338 if (SN < SN_LIMIT) continue; 339 340 bool valid = false; 341 valid |= (mask->data.U8[iy+1][ix] & crMask); 342 valid |= (ix > 0) ? (mask->data.U8[iy+1][ix-1] & crMask) : 0; 343 valid |= (ix <= mask->numCols) ? (mask->data.U8[iy+1][ix+1] & crMask) : 0; 344 345 if (!valid) continue; 346 mask->data.U8[iy][ix] |= crMask; 347 } 348 } 349 // next go down: 350 for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) { 351 // mark the pixels in this row to the left, then the right 352 for (int ix = 0; ix < pixels->numCols; ix++) { 353 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 354 if (SN < SN_LIMIT) continue; 355 356 bool valid = false; 357 valid |= (mask->data.U8[iy-1][ix] & crMask); 358 valid |= (ix > 0) ? (mask->data.U8[iy-1][ix-1] & crMask) : 0; 359 valid |= (ix <= mask->numCols) ? (mask->data.U8[iy-1][ix+1] & crMask) : 0; 360 361 if (!valid) continue; 362 mask->data.U8[iy][ix] |= crMask; 363 } 364 } 365 return true; 366 }
Note:
See TracChangeset
for help on using the changeset viewer.
