IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 29, 2010, 6:02:38 PM (16 years ago)
Author:
Paul Price
Message:

Fairly extensive change to make subtractions more stable on images with limited lit area in the presence of spatial variation. Took the polynomials which were scaled over the entire image and scale them only over the lit area. Removed some fprintf statements. Fixed the problem causing the background term to always come out 1.0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMask.c

    r24257 r26739  
    3838//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3939
    40 psImage *pmSubtractionMask(const psImage *mask1, const psImage *mask2, psImageMaskType maskVal,
    41                            int size, int footprint, float badFrac, pmSubtractionMode mode)
    42 {
    43     PS_ASSERT_IMAGE_NON_NULL(mask1, NULL);
    44     PS_ASSERT_IMAGE_TYPE(mask1, PS_TYPE_IMAGE_MASK, NULL);
    45     if (mask2) {
    46         PS_ASSERT_IMAGE_NON_NULL(mask2, NULL);
    47         PS_ASSERT_IMAGE_TYPE(mask2, PS_TYPE_IMAGE_MASK, NULL);
    48         PS_ASSERT_IMAGES_SIZE_EQUAL(mask2, mask1, NULL);
    49     }
     40psImage *pmSubtractionMask(psRegion *bounds, const pmReadout *ro1, const pmReadout *ro2,
     41                           psImageMaskType maskVal, int size, int footprint, float badFrac,
     42                           pmSubtractionMode mode)
     43{
     44    PM_ASSERT_READOUT_NON_NULL(ro1, NULL);
     45    PM_ASSERT_READOUT_IMAGE(ro1, NULL);
     46    PM_ASSERT_READOUT_MASK(ro1, NULL);
     47    PM_ASSERT_READOUT_NON_NULL(ro2, NULL);
     48    PM_ASSERT_READOUT_IMAGE(ro2, NULL);
     49    PM_ASSERT_READOUT_MASK(ro2, NULL);
     50    PS_ASSERT_IMAGES_SIZE_EQUAL(ro1->image, ro2->image, NULL);
    5051    PS_ASSERT_INT_NONNEGATIVE(size, NULL);
    5152    PS_ASSERT_INT_NONNEGATIVE(footprint, NULL);
     
    5556    }
    5657
    57     int numCols = mask1->numCols, numRows = mask1->numRows; // Size of the images
     58    int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Size of the images
    5859
    5960    // Dereference inputs for convenience
    60     psImageMaskType **data1 = mask1->data.PS_TYPE_IMAGE_MASK_DATA;
    61     psImageMaskType **data2 = NULL;
    62     if (mask2) {
    63         data2 = mask2->data.PS_TYPE_IMAGE_MASK_DATA;
    64     }
     61    psF32 **imageData1 = ro1->image->data.F32, **imageData2 = ro2->image->data.F32;
     62    psImageMaskType **maskData1 = ro1->mask->data.PS_TYPE_IMAGE_MASK_DATA,
     63        **maskData2 = ro2->mask->data.PS_TYPE_IMAGE_MASK_DATA;
    6564
    6665    // First, a pass through to determine the fraction of bad pixels
    67     if (isfinite(badFrac) && badFrac != 1.0) {
     66    if (bounds || (isfinite(badFrac) && badFrac != 1.0)) {
     67        int xMin = numCols, xMax = 0, yMin = numRows, yMax = 0; // Bounds of good pixels
    6868        int numBad = 0;                 // Number of bad pixels
    6969        for (int y = 0; y < numRows; y++) {
    7070            for (int x = 0; x < numCols; x++) {
    71                 if (data1[y][x] & maskVal) {
     71                if ((maskData1[y][x] & maskVal) || !isfinite(imageData1[y][x])) {
    7272                    numBad++;
    7373                    continue;
    7474                }
    75                 if (data2 && data2[y][x] & maskVal) {
     75                if ((maskData2[y][x] & maskVal) || !isfinite(imageData2[y][x])) {
    7676                    numBad++;
     77                    continue;
    7778                }
    78             }
    79         }
    80         if (numBad > badFrac * numCols * numRows) {
     79                xMin = PS_MIN(xMin, x);
     80                xMax = PS_MAX(xMax, x);
     81                yMin = PS_MIN(yMin, y);
     82                yMax = PS_MAX(yMax, y);
     83            }
     84        }
     85        if (bounds) {
     86            bounds->x0 = xMin;
     87            bounds->x1 = xMax;
     88            bounds->y0 = yMin;
     89            bounds->y1 = yMax;
     90        }
     91        if (isfinite(badFrac) && badFrac != 1.0 && numBad > badFrac * numCols * numRows) {
    8192            psError(PM_ERR_SMALL_AREA, true,
    8293                    "Fraction of bad pixels (%d/%d=%f) exceeds limit (%f)\n",
     
    117128    for (int y = 0; y < numRows; y++) {
    118129        for (int x = 0; x < numCols; x++) {
    119             if (data1[y][x] & maskVal) {
     130            if (maskData1[y][x] & maskVal) {
    120131                maskData[y][x] |= PM_SUBTRACTION_MASK_BAD_1;
    121132            }
    122             if (data2 && data2[y][x] & maskVal) {
     133            if (maskData2[y][x] & maskVal) {
    123134                maskData[y][x] |= PM_SUBTRACTION_MASK_BAD_2;
    124135            }
Note: See TracChangeset for help on using the changeset viewer.