IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23849


Ignore:
Timestamp:
Apr 14, 2009, 8:53:51 AM (17 years ago)
Author:
Paul Price
Message:

Fixing how stamps are found: ensuring NANs don't get into the stamp footprint, but trying not to make it go slow when looking for the maximum pixel in a subregion.

Location:
trunk/psModules/src/imcombine
Files:
4 edited

Legend:

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

    r21183 r23849  
    139139    bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolve
    140140
    141     if (!psImageConvolveMask(mask, mask, PM_SUBTRACTION_MASK_BAD_1,
    142                              PM_SUBTRACTION_MASK_CONVOLVE_1,
     141    if (!psImageConvolveMask(mask, mask, PM_SUBTRACTION_MASK_BAD_1, PM_SUBTRACTION_MASK_CONVOLVE_1,
    143142                             -size, size, -size, size)) {
    144143        psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad pixels from mask 1.");
     
    146145        return NULL;
    147146    }
    148     if (!psImageConvolveMask(mask, mask, PM_SUBTRACTION_MASK_BAD_2,
    149                              PM_SUBTRACTION_MASK_CONVOLVE_2,
     147    if (!psImageConvolveMask(mask, mask, PM_SUBTRACTION_MASK_BAD_2, PM_SUBTRACTION_MASK_CONVOLVE_2,
    150148                             -size, size, -size, size)) {
    151149        psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad pixels from mask 2.");
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r23740 r23849  
    7272{
    7373    psTrace("psModules.imcombine", 3, "Finding stamps...\n");
    74     *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, footprint,
     74    *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, size, footprint,
    7575                                      stampSpacing, mode);
    7676    if (!*stamps) {
     
    419419
    420420            if (sources) {
    421                 stamps = pmSubtractionStampsSetFromSources(sources, ro1->image, subMask, region, footprint,
    422                                                            stampSpacing, subMode);
     421                stamps = pmSubtractionStampsSetFromSources(sources, ro1->image, subMask, region, size,
     422                                                           footprint, stampSpacing, subMode);
    423423            } else if (stampsName && strlen(stampsName) > 0) {
    424                 stamps = pmSubtractionStampsSetFromFile(stampsName, ro1->image, subMask, region, footprint,
    425                                                         stampSpacing, subMode);
     424                stamps = pmSubtractionStampsSetFromFile(stampsName, ro1->image, subMask, region, size,
     425                                                        footprint, stampSpacing, subMode);
    426426            }
    427427
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r23839 r23849  
    8080// Is this position unmasked?
    8181static bool checkStampMask(int x, int y, // Coordinates of stamp
     82                           int numCols, int numRows, // Size of image
    8283                           const psImage *mask, // Mask
    8384                           pmSubtractionMode mode, // Mode for subtraction
    84                            int footprint // Footprint to check for Bad Stuff
     85                           int footprint, // Size of stamp
     86                           int border // Size of border
    8587                           )
    8688{
     89    // Check the footprint bounds
     90    if (x < border || x >= numCols - border || y < border || y >= numRows - border) {
     91        if (mask) {
     92            goto BAD_STAMP;
     93        }
     94        return false;
     95    }
     96
    8797    if (!mask) {
    8898        return true;
    8999    }
    90100
    91     bool clean = true;                  // Is the footprint clean?
    92     int numCols = mask->numCols, numRows = mask->numRows; // Size of image
    93 
    94     int xMin = PS_MAX(x - footprint, 0), xMax = PS_MIN(x + footprint, numCols - 1); // Bounds in x
    95     int yMin = PS_MAX(y - footprint, 0), yMax = PS_MIN(y + footprint, numRows - 1); // Bounds in y
    96 
    97     // Check the footprint bounds
    98     if (x < footprint || x >= numCols - footprint || y < footprint || y >= numRows - footprint) {
    99         clean = false;
    100         goto CHECK_STAMP_MASK_DONE;
    101 
    102     }
    103 
    104101    // Determine mask value
    105     psImageMaskType maskVal = PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_BAD_1 | PM_SUBTRACTION_MASK_BAD_2;
     102    psImageMaskType maskVal = PM_SUBTRACTION_MASK_BAD_1 | PM_SUBTRACTION_MASK_BAD_2 |
     103        PM_SUBTRACTION_MASK_BORDER;     // Mask value to check for
    106104    switch (mode) {
    107105      case PM_SUBTRACTION_MODE_1:
    108         maskVal |= PM_SUBTRACTION_MASK_CONVOLVE_1;
     106        maskVal |= PM_SUBTRACTION_MASK_CONVOLVE_1 | PM_SUBTRACTION_MASK_CONVOLVE_BAD_1;
    109107        break;
    110108      case PM_SUBTRACTION_MODE_2:
    111         maskVal |= PM_SUBTRACTION_MASK_CONVOLVE_2;
     109        maskVal |= PM_SUBTRACTION_MASK_CONVOLVE_2 | PM_SUBTRACTION_MASK_CONVOLVE_BAD_2;
    112110        break;
    113111      case PM_SUBTRACTION_MODE_UNSURE:
    114112      case PM_SUBTRACTION_MODE_DUAL:
    115         maskVal |= PM_SUBTRACTION_MASK_CONVOLVE_1 | PM_SUBTRACTION_MASK_CONVOLVE_2;
     113        maskVal |= PM_SUBTRACTION_MASK_CONVOLVE_1 | PM_SUBTRACTION_MASK_CONVOLVE_BAD_1 |
     114            PM_SUBTRACTION_MASK_CONVOLVE_2 | PM_SUBTRACTION_MASK_CONVOLVE_BAD_2;
    116115        break;
    117116      default:
     
    119118    }
    120119
    121     // Check the immediate pixel
    122     if (clean && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & (maskVal | PM_SUBTRACTION_MASK_REJ))) {
    123         goto CHECK_STAMP_MASK_DONE;
    124         clean = false;
     120    // Check the central pixel
     121    if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & (maskVal | PM_SUBTRACTION_MASK_REJ)) {
     122        goto BAD_STAMP;
    125123    }
    126124
    127125    // Check the footprint
    128     if (clean) {
    129         for (int j = yMin; j <= yMax; j++) {
    130             for (int i = xMin; i <= xMax; i++) {
    131                 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & maskVal) {
    132                     clean = false;
    133                     goto CHECK_STAMP_MASK_DONE;
    134                 }
     126    int xMin = PS_MAX(x - footprint, 0), xMax = PS_MIN(x + footprint, numCols - 1); // Bounds in x
     127    int yMin = PS_MAX(y - footprint, 0), yMax = PS_MIN(y + footprint, numRows - 1); // Bounds in y
     128    for (int j = yMin; j <= yMax; j++) {
     129        for (int i = xMin; i <= xMax; i++) {
     130            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] & maskVal) {
     131                goto BAD_STAMP;
    135132            }
    136133        }
    137134    }
    138135
    139  CHECK_STAMP_MASK_DONE:
    140     if (!clean) {
    141         // Mask the footprint, so we don't select something near it again
    142         for (int j = yMin; j <= yMax; j++) {
    143             for (int i = xMin; i <= xMax; i++) {
    144                 mask->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= PM_SUBTRACTION_MASK_REJ;
    145             }
    146         }
    147     }
    148 
    149     return clean;
     136    return true;
     137
     138BAD_STAMP:
     139    // Stamp is bad, so mark it as such so we don't find it again
     140    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ;
     141    return false;
    150142}
    151143
     
    279271pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, const psImage *image,
    280272                                                const psImage *subMask, const psRegion *region,
    281                                                 float threshold, int footprint, float spacing,
     273                                                float threshold, int size, int footprint, float spacing,
    282274                                                pmSubtractionMode mode)
    283275{
     
    289281        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, NULL);
    290282    }
     283    PS_ASSERT_INT_POSITIVE(size, NULL);
    291284    PS_ASSERT_INT_NONNEGATIVE(footprint, NULL);
    292285    PS_ASSERT_FLOAT_LARGER_THAN(spacing, 0.0, NULL);
     
    309302
    310303    int numRows = image->numRows, numCols = image->numCols; // Size of image
     304    int border = size + footprint;      // Border size
    311305
    312306    if (!stamps) {
     
    367361                    for (int x = subRegion->x0; x <= subRegion->x1; x++) {
    368362                        if (image->data.F32[y][x] > fluxStamp &&
    369                             checkStampMask(x, y, subMask, mode, footprint)) {
     363                            checkStampMask(x, y, numCols, numRows, subMask, mode, footprint, border)) {
    370364                            fluxStamp = image->data.F32[y][x];
    371365                            xStamp = x;
     
    419413pmSubtractionStampList *pmSubtractionStampsSet(const psVector *x, const psVector *y,
    420414                                               const psImage *image, const psImage *subMask,
    421                                                const psRegion *region, int footprint, float spacing,
    422                                                pmSubtractionMode mode)
     415                                               const psRegion *region, int size, int footprint,
     416                                               float spacing, pmSubtractionMode mode)
    423417
    424418{
     
    432426        PS_ASSERT_IMAGE_NON_NULL(subMask, NULL);
    433427        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, NULL);
    434         if (image) {
    435             PS_ASSERT_IMAGE_NON_NULL(image, NULL);
    436             PS_ASSERT_IMAGES_SIZE_EQUAL(image, subMask, NULL);
    437         }
    438     }
     428        PS_ASSERT_IMAGES_SIZE_EQUAL(image, subMask, NULL);
     429    }
     430    PS_ASSERT_INT_POSITIVE(size, NULL);
     431    PS_ASSERT_INT_POSITIVE(footprint, NULL);
    439432    PS_ASSERT_FLOAT_LARGER_THAN(spacing, 0.0, NULL);
    440433
     
    443436                                                                 region, footprint, spacing); // Stamp list
    444437    int numStamps = stamps->num;        // Number of stamps
     438    int numCols = image->numCols, numRows = image->numRows; // Size of image
     439    int border = footprint + size;      // Border size
    445440
    446441    psString ds9name = NULL;            // Filename for ds9 region file
     
    471466            continue;
    472467        }
    473         if (!checkStampMask(xPix, yPix, subMask, mode, footprint)) {
     468        if (!checkStampMask(xPix, yPix, numCols, numRows, subMask, mode, footprint, border)) {
    474469            // Not a good stamp
    475470            psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because bad mask",
     
    613608pmSubtractionStampList *pmSubtractionStampsSetFromSources(const psArray *sources, const psImage *image,
    614609                                                          const psImage *subMask, const psRegion *region,
    615                                                           int footprint, float spacing,
     610                                                          int size, int footprint, float spacing,
    616611                                                          pmSubtractionMode mode)
    617612{
     
    642637    y->n = numOut;
    643638
    644     pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region,
     639    pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, size,
    645640                                                            footprint, spacing, mode); // Stamps to return
    646641    psFree(x);
     
    657652pmSubtractionStampList *pmSubtractionStampsSetFromFile(const char *filename, const psImage *image,
    658653                                                       const psImage *subMask, const psRegion *region,
    659                                                        int footprint, float spacing, pmSubtractionMode mode)
     654                                                       int size, int footprint, float spacing,
     655                                                       pmSubtractionMode mode)
    660656{
    661657    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     
    673669    psBinaryOp(y, y, "-", psScalarAlloc(1.0, PS_TYPE_F32));
    674670
    675     pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, footprint,
     671    pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, size, footprint,
    676672                                                            spacing, mode);
    677673    psFree(data);
  • trunk/psModules/src/imcombine/pmSubtractionStamps.h

    r23839 r23849  
    7878                                                const psRegion *region, ///< Region to search, or NULL
    7979                                                float threshold, ///< Threshold for stamps in the image
     80                                                int size, ///< Kernel half-size
    8081                                                int footprint, ///< Half-size for stamps
    8182                                                float spacing, ///< Rough spacing for stamps
     
    8990                                               const psImage *mask, ///< Mask, or NULL
    9091                                               const psRegion *region, ///< Region to search, or NULL
     92                                               int size, ///< Kernel half-size
    9193                                               int footprint, ///< Half-size for stamps
    9294                                               float spacing, ///< Rough spacing for stamps
     
    100102    const psImage *subMask,             ///< Mask, or NULL
    101103    const psRegion *region,             ///< Region to search, or NULL
     104    int size,                           ///< Kernel half-size
    102105    int footprint,                      ///< Half-size for stamps
    103106    float spacing,                      ///< Rough spacing for stamps
     
    111114    const psImage *subMask,             ///< Mask, or NULL
    112115    const psRegion *region,             ///< Region to search, or NULL
     116    int size,                           ///< Kernel half-size
    113117    int footprint,                      ///< Half-size for stamps
    114118    float spacing,                      ///< Rough spacing for stamps
Note: See TracChangeset for help on using the changeset viewer.