IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15305


Ignore:
Timestamp:
Oct 12, 2007, 1:00:37 PM (19 years ago)
Author:
Paul Price
Message:

Will fail without trying hard if there are not enough good pixels.

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

Legend:

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

    r14870 r15305  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-09-17 21:40:22 $
     6 *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-10-12 23:00:36 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    459459
    460460psImage *pmSubtractionMask(const psImage *refMask, const psImage *inMask, psMaskType maskVal,
    461                            int size, int footprint)
     461                           int size, int footprint, float badFrac)
    462462{
    463463    PS_ASSERT_IMAGE_NON_NULL(refMask, NULL);
     
    470470    PS_ASSERT_INT_NONNEGATIVE(size, NULL);
    471471    PS_ASSERT_INT_NONNEGATIVE(footprint, NULL);
     472    if (isfinite(badFrac)) {
     473        PS_ASSERT_FLOAT_LARGER_THAN(badFrac, 0.0, NULL);
     474        PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(badFrac, 1.0, NULL);
     475    }
    472476
    473477    // Size of the images
     
    475479    int numRows = refMask->numRows;
    476480
     481    // Dereference inputs for convenience
     482    psMaskType **inData = NULL;
     483    if (inMask) {
     484        inData = inMask->data.PS_TYPE_MASK_DATA;
     485    }
     486    psMaskType **refData = refMask->data.PS_TYPE_MASK_DATA;
     487
     488    // First, a pass through to determine the fraction of bad pixels
     489    if (isfinite(badFrac) && badFrac != 1.0) {
     490        int numBad = 0;                 // Number of bad pixels
     491        for (int y = 0; y < numRows; y++) {
     492            for (int x = 0; x < numCols; x++) {
     493                if (inData && inData[y][x] & maskVal) {
     494                    numBad++;
     495                    continue;
     496                }
     497                if (refData[y][x] & maskVal) {
     498                    numBad++;
     499                }
     500            }
     501        }
     502        if (numBad > badFrac * numCols * numRows) {
     503            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Fraction of bad pixels (%d/%d) exceeds limit (%f)\n",
     504                    numBad, numCols * numRows, badFrac);
     505            return NULL;
     506        }
     507    }
     508
    477509    // Worried about the masks for bad pixels and bad stamps colliding, so make our own mask
    478510    psImage *mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // The global mask
    479511    psImageInit(mask, 0);
    480 
    481     // Dereference for convenience
    482     psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA;
    483     psMaskType **inData = NULL;
    484     if (inMask) {
    485         inData = inMask->data.PS_TYPE_MASK_DATA;
    486     }
    487     psMaskType **refData = refMask->data.PS_TYPE_MASK_DATA;
     512    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA; // Dereference for convenience
    488513
    489514    // Block out a border around the edge of the image
     
    510535        }
    511536    }
     537
     538    // XXX Could do something smarter here --- we will get images that are predominantly masked (where the
     539    // skycell isn't overlapped by a large fraction by the observation), so that convolving around every bad
     540    // pixel is wasting time.  As a first cut, I've put in a check on the fraction of bad pixels, but we could
     541    // imagine looking for the edge of big regions and convolving just at the edge.
    512542
    513543    // Mask the bad pixels, and around them
  • trunk/psModules/src/imcombine/pmSubtraction.h

    r14801 r15305  
    66 * @author GLG, MHPCC
    77 *
    8  * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-09-10 20:10:05 $
     8 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-10-12 23:00:37 $
    1010 *
    1111 * Copyright 2004-207 Institute for Astronomy, University of Hawaii
     
    3737                           psMaskType maskVal, ///< Value to mask out
    3838                           int size, ///< Half-size of the kernel (pmSubtractionKernels.size)
    39                            int footprint ///< Half-size of the kernel footprint
     39                           int footprint, ///< Half-size of the kernel footprint
     40                           float badFrac ///< Maximum fraction of bad input pixels to accept
    4041    );
    4142
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r15285 r15305  
    9898                        int inner, int ringsOrder, int binning, bool optimum, const psVector *optFWHMs,
    9999                        int optOrder, float optThreshold, int iter, float rej, psMaskType maskBad,
    100                         psMaskType maskBlank)
     100                        psMaskType maskBlank, float badFrac)
    101101{
    102102    PS_ASSERT_PTR_NON_NULL(convolved, false);
     
    165165    // Don't care about maskBad
    166166    // Don't care about maskBlank
     167    if (isfinite(badFrac)) {
     168        PS_ASSERT_FLOAT_LARGER_THAN(badFrac, 0.0, NULL);
     169        PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(badFrac, 1.0, NULL);
     170    }
    167171
    168172    // If the stamp footprint is smaller than the kernel size, then we won't get much signal in the outer
     
    219223    memCheck("start");
    220224
    221     subMask = pmSubtractionMask(reference->mask, inMask, maskBad, size, footprint);
     225    subMask = pmSubtractionMask(reference->mask, inMask, maskBad, size, footprint, badFrac);
     226    if (subMask) {
     227        psError(PS_ERR_UNKNOWN, false, "Unable to generate subtraction mask.");
     228        return false;
     229    }
    222230
    223231    memCheck("mask");
  • trunk/psModules/src/imcombine/pmSubtractionMatch.h

    r14805 r15305  
    3737                        float rej,      ///< Rejection threshold
    3838                        psMaskType maskBad, ///< Value to mask
    39                         psMaskType maskBlank ///< Mask for blank region
     39                        psMaskType maskBlank, ///< Mask for blank region
     40                        float badFrac   ///< Maximum fraction of bad input pixels to accept
    4041    );
    4142
Note: See TracChangeset for help on using the changeset viewer.