Changeset 19163 for trunk/psModules/src/camera/pmFPAMaskWeight.c
- Timestamp:
- Aug 22, 2008, 12:25:22 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAMaskWeight.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAMaskWeight.c
r17732 r19163 12 12 #include "pmHDUGenerate.h" 13 13 #include "pmFPAMaskWeight.h" 14 15 #define PIXELS_BUFFER 100 // Size of buffer for allocating pixel lists 14 16 15 17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 431 433 return true; 432 434 } 435 436 437 bool pmReadoutInterpolateBadPixels(pmReadout *readout, psMaskType maskVal, psImageInterpolateMode mode, 438 float poorFrac, psMaskType maskPoor, psMaskType maskBad) 439 { 440 PM_ASSERT_READOUT_NON_NULL(readout, false); 441 PM_ASSERT_READOUT_IMAGE(readout, false); 442 PM_ASSERT_READOUT_MASK(readout, false); 443 if (!maskVal) { 444 return true; 445 } 446 447 psImage *image = readout->image; // Image 448 psImage *mask = readout->mask; // Mask 449 psImage *weight = readout->weight; // Weight map 450 451 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(mode, image, weight, mask, maskVal, 452 NAN, NAN, maskBad, maskPoor, poorFrac); 453 interp->shifting = false; // Turn off "exact shifts" so we get proper interpolation 454 455 int numCols = mask->numCols, numRows = mask->numRows; // Size of image 456 457 psPixels *pixels = psPixelsAllocEmpty(PIXELS_BUFFER); // Pixels that have been interpolated 458 psVector *imagePix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_F32); // Corresponding values for image 459 psVector *weightPix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_F32); // Corresponding values for weight 460 psVector *maskPix = psVectorAllocEmpty(PIXELS_BUFFER, PS_TYPE_MASK); // Corresponding values for mask 461 462 long numBad = 0; // Number of bad pixels interpolated 463 for (int y = 0; y < numRows; y++) { 464 for (int x = 0; x < numCols; x++) { 465 if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) { 466 double imageValue, weightValue; // Image and weight value from interpolation 467 psMaskType maskValue = 0; // Mask value from interpolation 468 psImageInterpolateStatus status = psImageInterpolate(&imageValue, &weightValue, &maskValue, 469 x, y, interp); 470 if (status == PS_INTERPOLATE_STATUS_ERROR || status == PS_INTERPOLATE_STATUS_OFF) { 471 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate readout at %d,%d", x, y); 472 psFree(interp); 473 psFree(pixels); 474 psFree(imagePix); 475 psFree(weightPix); 476 psFree(maskPix); 477 return false; 478 } 479 if (status == PS_INTERPOLATE_STATUS_BAD) { 480 // It's still bad: couldn't interpolate enough 481 continue; 482 } 483 484 pixels = psPixelsAdd(pixels, PIXELS_BUFFER, x, y); 485 imagePix = psVectorExtend(imagePix, PIXELS_BUFFER, 1); 486 weightPix = psVectorExtend(weightPix, PIXELS_BUFFER, 1); 487 maskPix = psVectorExtend(maskPix, PIXELS_BUFFER, 1); 488 imagePix->data.F32[numBad] = imageValue; 489 weightPix->data.F32[numBad] = weightValue; 490 maskPix->data.PS_TYPE_MASK_DATA[numBad] = maskValue; 491 numBad++; 492 } 493 } 494 } 495 496 psFree(interp); 497 498 for (long i = 0; i < numBad; i++) { 499 int x = pixels->data[i].x, y = pixels->data[i].y; // Coordinates of pixel 500 image->data.F32[y][x] = imagePix->data.F32[i]; 501 weight->data.F32[y][x] = weightPix->data.F32[i]; 502 mask->data.PS_TYPE_MASK_DATA[y][x] = maskPix->data.PS_TYPE_MASK_DATA[i]; 503 } 504 505 psFree(pixels); 506 psFree(imagePix); 507 psFree(weightPix); 508 psFree(maskPix); 509 510 psLogMsg("psModules.camera", PS_LOG_INFO, "Interpolated over %ld pixels", numBad); 511 512 return true; 513 }
Note:
See TracChangeset
for help on using the changeset viewer.
