Changeset 20978
- Timestamp:
- Dec 14, 2008, 9:18:03 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20081214/psphot/src/psphotSourceSize.c
r20938 r20978 2 2 # include <gsl/gsl_sf_gamma.h> 3 3 4 // XXX This should be a recipe variable 5 # define SN_LIMIT 5.0 6 4 7 static float psphotModelContour(const psImage *image, const psImage *weight, const psImage *mask, 5 8 psMaskType maskVal, const pmModel *model, float Ro); 6 9 7 bool psphotMaskCosmicRay_Old (pm Source *source, psMaskType maskVal, psMaskType crMask);10 bool psphotMaskCosmicRay_Old (pmReadout *readout, pmSource *source, psMaskType maskVal, psMaskType crMask); 8 11 bool psphotMaskCosmicRay_New (psImage *mask, pmSource *source, psMaskType maskVal, psMaskType crMask); 9 12 … … 44 47 soft = 0.0; 45 48 } 49 50 psphotVisualShowSNLimit (readout, SN_LIMIT); 46 51 47 52 // loop over all source … … 161 166 if (source->crNsigma > CR_NSIGMA_LIMIT) { 162 167 // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask); 163 psphotMaskCosmicRay_Old (source, maskVal, crMask); 168 // psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask); 169 psphotMaskCosmicRay_Old (readout, source, maskVal, crMask); 164 170 } 165 171 } … … 275 281 if (!footprint) { 276 282 // if we have not footprint, use the old code to mask by isophot 277 psphotMaskCosmicRay_Old (source, maskVal, crMask); 283 // XXX this is broken, but we probably will not use it 284 psphotMaskCosmicRay_Old (NULL, source, maskVal, crMask); 278 285 return true; 279 286 } … … 281 288 if (!footprint->spans) { 282 289 // if we have not footprint, use the old code to mask by isophot 283 psphotMaskCosmicRay_Old (source, maskVal, crMask); 290 // XXX this is broken, but we probably will not use it 291 psphotMaskCosmicRay_Old (NULL, source, maskVal, crMask); 284 292 return true; 285 293 } … … 300 308 } 301 309 302 bool psphotMaskCosmicRay_Old (pm Source *source, psMaskType maskVal, psMaskType crMask) {310 bool psphotMaskCosmicRay_Old (pmReadout *readout, pmSource *source, psMaskType maskVal, psMaskType crMask) { 303 311 304 312 source->mode |= PM_SOURCE_MODE_CR_LIMIT; … … 306 314 psAssert (peak, "NULL peak"); 307 315 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 316 // XXX should we be doing this on the smoothed image?? 317 psImage *pixels = readout->image; 318 psImage *mask = readout->mask; 319 psImage *weight = readout->weight; 314 320 315 321 int xo = peak->x - pixels->col0; 316 322 int yo = peak->y - pixels->row0; 317 318 // mark the pixels in this row to the left, then the right 323 bool rowDone; 324 325 psVector *xf = psVectorAllocEmpty (64, PS_TYPE_F32); 326 psVector *yf = psVectorAllocEmpty (64, PS_TYPE_F32); 327 328 // mark the pixels in this row to the left, then the right. record the bounds of the valid pixel (SN >= SN_LIMIT) 329 int xs = 0; 330 int xe = pixels->numCols; 319 331 for (int ix = xo; ix >= 0; ix--) { 320 332 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 } 333 if (SN < SN_LIMIT) { 334 xs = ix + 1; 335 break; 336 } 337 mask->data.U8[yo][ix] |= crMask; 338 psVectorAppend (xf, (float) ix); 339 psVectorAppend (yf, (float) yo); 324 340 } 325 341 for (int ix = xo + 1; ix < pixels->numCols; ix++) { 326 342 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 } 343 if (SN < SN_LIMIT) { 344 xe = ix; 345 break; 346 } 347 mask->data.U8[yo][ix] |= crMask; 348 psVectorAppend (xf, (float) ix); 349 psVectorAppend (yf, (float) yo); 350 } 351 psphotVisualShowCRMask (xf, yf); 352 353 int startXs = xs; 354 int startXe = xe; 355 rowDone = false; 331 356 332 357 // 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 } 358 // first go down: 359 for (int iy = yo - 1; !rowDone && (iy >= 0); iy--) { 360 rowDone = true; // we are not done if any valid pixels are found a row 361 362 // given the range xs to xe (valid pixel range from previous row), find the valid 363 // pixels within this range, and extend if the ends are valid 364 365 // newXs,newXe will define the valid pixel range for this row 366 int newXs = xe; 367 int newXe = xs; 368 369 // first, try all of the pixels in the valid range (xs < x < xe guaranteed to be real pixels) 370 for (int ix = xs; ix < xe; ix++) { 371 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 372 if (SN < SN_LIMIT) { 373 continue; 374 } 375 newXs = PS_MIN (newXs, ix); 376 newXe = PS_MAX (newXe, ix + 1); 377 rowDone = false; 378 mask->data.U8[iy][ix] |= crMask; 379 psVectorAppend (xf, (float) ix); 380 psVectorAppend (yf, (float) iy); 381 } 382 383 // next, try the pixels to the left of the valid range for the previous row 384 for (int ix = xs - 1; ix >= 0; ix--) { 385 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 386 if (SN < SN_LIMIT) { 387 newXs = ix + 1; 388 break; 389 } 390 rowDone = false; 391 mask->data.U8[iy][ix] |= crMask; 392 psVectorAppend (xf, (float) ix); 393 psVectorAppend (yf, (float) iy); 394 } 395 396 // finally, try the pixels to the right of the valid range for the previous row 397 for (int ix = xe; ix < pixels->numCols; ix++) { 398 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 399 if (SN < SN_LIMIT) { 400 newXe = ix; 401 break; 402 } 403 rowDone = false; 404 mask->data.U8[iy][ix] |= crMask; 405 psVectorAppend (xf, (float) ix); 406 psVectorAppend (yf, (float) iy); 407 } 408 409 xs = newXs; 410 xe = newXe; 411 } 412 psphotVisualShowCRMask (xf, yf); 413 414 xs = startXs; 415 xe = startXe; 416 rowDone = false; 417 418 // for each of the neighboring rows, mark the high pixels if they have a marked neighbor 419 // first go down: 420 for (int iy = yo + 1; !rowDone && (iy < pixels->numRows); iy++) { 421 rowDone = true; // we are not done if any valid pixels are found a row 422 423 // given the range xs to xe (valid pixel range from previous row), find the valid 424 // pixels within this range, and extend if the ends are valid 425 426 // newXs,newXe will define the valid pixel range for this row 427 int newXs = xe; 428 int newXe = xs; 429 430 // first, try all of the pixels in the valid range (xs < x < xe guaranteed to be real pixels) 431 for (int ix = xs; ix < xe; ix++) { 432 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 433 if (SN < SN_LIMIT) { 434 continue; 435 } 436 newXs = PS_MIN (newXs, ix); 437 newXe = PS_MAX (newXe, ix + 1); 438 rowDone = false; 439 mask->data.U8[iy][ix] |= crMask; 440 psVectorAppend (xf, (float) ix); 441 psVectorAppend (yf, (float) iy); 442 } 443 444 // next, try the pixels to the left of the valid range for the previous row 445 for (int ix = xs - 1; ix >= 0; ix--) { 446 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 447 if (SN < SN_LIMIT) { 448 newXs = ix + 1; 449 break; 450 } 451 rowDone = false; 452 mask->data.U8[iy][ix] |= crMask; 453 psVectorAppend (xf, (float) ix); 454 psVectorAppend (yf, (float) iy); 455 } 456 457 // finally, try the pixels to the right of the valid range for the previous row 458 for (int ix = xe; ix < pixels->numCols; ix++) { 459 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]); 460 if (SN < SN_LIMIT) { 461 newXe = ix; 462 break; 463 } 464 rowDone = false; 465 mask->data.U8[iy][ix] |= crMask; 466 psVectorAppend (xf, (float) ix); 467 psVectorAppend (yf, (float) iy); 468 } 469 470 xs = newXs; 471 xe = newXe; 472 } 473 474 psphotVisualShowCRMask (xf, yf); 475 psFree (xf); 476 psFree (yf); 477 365 478 return true; 366 479 }
Note:
See TracChangeset
for help on using the changeset viewer.
