IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24066


Ignore:
Timestamp:
May 4, 2009, 6:29:42 PM (17 years ago)
Author:
Paul Price
Message:

Search around provided stamp centre for a suitable stamp. If there's
a lot of masking going on, the centre of the stamp may not be
suitable, but there's no reason why we can't offset a bit.
Attempt to address ticket 1235.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r23937 r24066  
    7878}
    7979
    80 // Is this position unmasked?
    81 static bool checkStampMask(int x, int y, // Coordinates of stamp
    82                            int numCols, int numRows, // Size of image
    83                            const psImage *mask, // Mask
    84                            pmSubtractionMode mode, // Mode for subtraction
    85                            int footprint, // Size of stamp
    86                            int border // Size of border
    87                            )
    88 {
    89     // Check the footprint bounds
    90     if (x < border || x >= numCols - border || y < border || y >= numRows - border) {
    91         return false;
    92     }
    93 
    94     if (!mask) {
    95         return true;
    96     }
    97 
    98     // Check the central pixel
    99     if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_REJ)) {
    100         mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ;
    101         return false;
    102     }
    103 
    104     return true;
     80
     81// Search a region for a suitable stamp
     82bool stampSearch(int *xStamp, int *yStamp, // Coordinates of stamp, to return
     83                 float *fluxStamp, // Flux of stamp, to return
     84                 const psImage *image1, const psImage *image2, // Images to search
     85                 float thresh1, float thresh2, // Thresholds for images
     86                 const psImage *subMask, // Subtraction mask
     87                 int xMin, int xMax, int yMin, int yMax, // Bounds of search
     88                 int numCols, int numRows, // Size of images
     89                 int border             // Border around image
     90    )
     91{
     92    bool found = false;                 // Found a suitable stamp?
     93    *fluxStamp = -INFINITY;             // Flux of best stamp
     94
     95    // Ensure we're not going to go outside the bounds of the image
     96    xMin = PS_MAX(border, xMin);
     97    xMax = PS_MIN(numCols - border - 1, xMax);
     98    yMin = PS_MAX(border, yMin);
     99    yMax = PS_MIN(numRows - border - 1, yMax);
     100
     101    for (int y = yMin; y <= yMax; y++) {
     102        for (int x = xMin; x <= xMax; x++) {
     103            if ((image1 && image1->data.F32[y][x] < thresh1) ||
     104                (image2 && image2->data.F32[y][x] < thresh2)) {
     105                continue;
     106            }
     107
     108            if (subMask && subMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] &
     109                (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_REJ)) {
     110                return false;
     111            }
     112
     113            // We take the MIN to attempt to avoid transients in both images
     114            float flux = (image1 && image2) ? PS_MIN(image1->data.F32[y][x], image2->data.F32[y][x]) :
     115                ((image1) ? image1->data.F32[y][x] : image2->data.F32[y][x]); // Flux at pixel
     116            if (flux > *fluxStamp) {
     117                *xStamp = x;
     118                *yStamp = y;
     119                *fluxStamp = flux;
     120                found = true;
     121            }
     122        }
     123    }
     124
     125    return found;
    105126}
    106127
     
    314335            numSearch++;
    315336
    316             float xStamp = 0, yStamp = 0;  // Coordinates of stamp
    317             float fluxStamp = NAN;          // Flux of stamp
    318             bool goodStamp = false;         // Found a good stamp?
     337            int xStamp = 0, yStamp = 0; // Coordinates of stamp
     338            float fluxStamp = -INFINITY; // Flux of stamp
     339            bool goodStamp = false;     // Found a good stamp?
    319340
    320341            // A couple different ways of finding stamps:
     
    324345                psVector *fluxList = stamps->flux->data[i]; // List of stamp fluxes
    325346
    326                 // Take stamp off the top of the (sorted) list
    327                 if (xList->n > 0) {
    328                     int index = xList->n - 1; // Index of new stamp
    329                     xStamp = xList->data.F32[index];
    330                     yStamp = yList->data.F32[index];
    331                     fluxStamp = fluxList->data.F32[index];
     347                // Take stamps off the top of the (sorted) list
     348                for (int j = xList->n - 1; j >= 0 && !goodStamp; j--) {
     349                    int xCentre = xList->data.F32[j] + 0.5, yCentre = yList->data.F32[j] + 0.5;// Stamp centre
    332350
    333351                    // Chop off the top of the list
    334                     xList->n = index;
    335                     yList->n = index;
    336                     fluxList->n = index;
    337 
    338                     goodStamp = true;
    339                     int x = xStamp + 0.5, y = yStamp + 0.5; // Pixel location
    340                     if (image1 && image1->data.F32[y][x] < thresh1) {
    341                         goodStamp = false;
    342                     } else if (image2 && image2->data.F32[y][x] < thresh2) {
    343                         goodStamp = false;
    344                     }
    345                 } else {
    346                     psTrace("psModules.imcombine", 9, "No sources in subregion %d", i);
     352                    xList->n = j;
     353                    yList->n = j;
     354                    fluxList->n = j;
     355
     356                    // Fish around a bit to see if we can find a pixel that isn't masked
     357                    psTrace("psModules.imcombine", 7, "Searching for stamp %d around %d,%d\n",
     358                            i, xCentre, yCentre);
     359
     360                    // Search bounds
     361                    int search = footprint - size; // Search radius
     362                    int xMin = PS_MAX(border, xCentre - search);
     363                    int xMax = PS_MIN(numCols - border -1, xCentre + search);
     364                    int yMin = PS_MAX(border, yCentre - search);
     365                    int yMax = PS_MIN(numRows - border - 1, yCentre + search);
     366
     367                    goodStamp = stampSearch(&xStamp, &yStamp, &fluxStamp, image1, image2, thresh1, thresh2,
     368                                            subMask, xMin, xMax, yMin, yMax, numCols, numRows, border);
    347369                }
    348370            } else {
    349371                // Use a simple method of automatically finding stamps --- take the highest pixel in the
    350372                // subregion
    351                 fluxStamp = 0.0;
    352373                psRegion *subRegion = stamps->regions->data[i]; // Sub-region of interest
    353374
    354                 const psImage *image = NULL; // Image for flux of stamp
    355                 switch (mode) {
    356                   case PM_SUBTRACTION_MODE_1:
    357                     image = image2 ? image2 : image1;
    358                     break;
    359                   case PM_SUBTRACTION_MODE_2:
    360                     image = image1 ? image1 : image2;
    361                     break;
    362                   case PM_SUBTRACTION_MODE_UNSURE:
    363                   case PM_SUBTRACTION_MODE_DUAL:
    364                     // If both are available, we'll take the MIN value below in the hope of rejecting
    365                     // transients in both
    366                     image = (image1 && image2) ? NULL : (image1 ? image1 : image2);
    367                   default:
    368                     psAbort("Unrecognised mode: %x", mode);
    369                 }
    370 
    371                 for (int y = subRegion->y0; y <= subRegion->y1; y++) {
    372                     for (int x = subRegion->x0; x <= subRegion->x1; x++) {
    373                         if ((image1 && image1->data.F32[y][x] < thresh1) ||
    374                             (image2 && image2->data.F32[y][x] < thresh2)) {
    375                             continue;
    376                         }
    377                         float value = image ? image->data.F32[y][x] :
    378                             PS_MIN(image1->data.F32[y][x], image2->data.F32[y][x]); // Value of image
    379                         if (value > fluxStamp &&
    380                             checkStampMask(x, y, numCols, numRows, subMask, mode, footprint, border)) {
    381                             fluxStamp = image->data.F32[y][x];
    382                             xStamp = x;
    383                             yStamp = y;
    384                             goodStamp = true;
    385                         }
    386                     }
    387                 }
     375                goodStamp = stampSearch(&xStamp, &yStamp, &fluxStamp, image1, image2, thresh1, thresh2,
     376                                        subMask, subRegion->x0, subRegion->x1, subRegion->y0, subRegion->y1,
     377                                        numCols, numRows, border);
    388378            }
    389379
     
    453443                                                                 region, footprint, spacing); // Stamp list
    454444    int numStamps = stamps->num;        // Number of stamps
    455     int numCols = image->numCols, numRows = image->numRows; // Size of image
    456     int border = footprint + size;      // Border size
    457445
    458446    psString ds9name = NULL;            // Filename for ds9 region file
     
    480468            psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because outside region",
    481469                    xPix, yPix);
    482             pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "magenta");
    483             continue;
    484         }
    485         if (!checkStampMask(xPix, yPix, numCols, numRows, subMask, mode, footprint, border)) {
    486             // Not a good stamp
    487             psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because bad mask",
    488                     xPix, yPix);
    489470            pmSubtractionStampPrint(ds9, xPix, yPix, footprint, "red");
    490471            continue;
Note: See TracChangeset for help on using the changeset viewer.