IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23937


Ignore:
Timestamp:
Apr 20, 2009, 2:48:42 PM (17 years ago)
Author:
Paul Price
Message:

Implement stamp thresholds on both images. This is to avoid transients being selected as stamps.

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

Legend:

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

    r23851 r23937  
    6464                      psImage *variance,  // Variance map
    6565                      const psRegion *region, // Region of interest, or NULL
    66                       float threshold,  // Threshold for stamp finding
     66                      float thresh1,  // Threshold for stamp finding on readout 1
     67                      float thresh2,  // Threshold for stamp finding on readout 2
    6768                      float stampSpacing, // Spacing between stamps
    6869                      int size,         // Kernel half-size
     
    7273{
    7374    psTrace("psModules.imcombine", 3, "Finding stamps...\n");
    74     *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, size, footprint,
    75                                       stampSpacing, mode);
     75
     76    psImage *image1 = ro1 ? ro1->image : NULL, *image2 = ro2 ? ro2->image : NULL; // Images of interest
     77
     78    *stamps = pmSubtractionStampsFind(*stamps, image1, image2, subMask, region, thresh1, thresh2,
     79                                      size, footprint, stampSpacing, mode);
    7680    if (!*stamps) {
    7781        psError(psErrorCodeLast(), false, "Unable to find stamps.");
     
    392396    }
    393397
     398    float stampThresh1 = NAN, stampThresh2 = NAN; // Stamp thresholds for images
    394399    {
    395400        psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for backgroun
    396         if (!psImageBackground(bg, NULL, ro1->image, ro1->mask, maskVal, rng)) {
    397             psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
    398             psFree(bg);
    399             psFree(rng);
    400             goto MATCH_ERROR;
    401         }
    402         threshold = bg->robustMedian + threshold * bg->robustStdev;
     401        if (ro1) {
     402            if (!psImageBackground(bg, NULL, ro1->image, ro1->mask, maskVal, rng)) {
     403                psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
     404                psFree(bg);
     405                psFree(rng);
     406                goto MATCH_ERROR;
     407            }
     408            stampThresh1 = bg->robustMedian + threshold * bg->robustStdev;
     409        }
     410        if (ro2) {
     411            if (!psImageBackground(bg, NULL, ro2->image, ro2->mask, maskVal, rng)) {
     412                psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
     413                psFree(bg);
     414                psFree(rng);
     415                goto MATCH_ERROR;
     416            }
     417            stampThresh2 = bg->robustMedian + threshold * bg->robustStdev;
     418        }
    403419        psFree(bg);
    404420    }
     
    428444            // We get the stamps here; we will also attempt to get stamps at the first iteration, but it
    429445            // doesn't matter.
    430             if (!getStamps(&stamps, ro1, ro2, subMask, variance, NULL, threshold, stampSpacing,
    431                            size, footprint, subMode)) {
     446            if (!getStamps(&stamps, ro1, ro2, subMask, variance, NULL, stampThresh1, stampThresh2,
     447                           stampSpacing, size, footprint, subMode)) {
    432448                goto MATCH_ERROR;
    433449            }
     
    490506                psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k);
    491507
    492                 if (!getStamps(&stamps, ro1, ro2, subMask, variance, region, threshold, stampSpacing,
    493                                size, footprint, subMode)) {
     508                if (!getStamps(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2,
     509                               stampSpacing, size, footprint, subMode)) {
    494510                    goto MATCH_ERROR;
    495511                }
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r23851 r23937  
    232232
    233233
    234 pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, const psImage *image,
    235                                                 const psImage *subMask, const psRegion *region,
    236                                                 float threshold, int size, int footprint, float spacing,
     234pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, const psImage *image1,
     235                                                const psImage *image2, const psImage *subMask,
     236                                                const psRegion *region, float thresh1, float thresh2,
     237                                                int size, int footprint, float spacing,
    237238                                                pmSubtractionMode mode)
    238239{
    239     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
    240     PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);
     240    if (!image1 && !image2) {
     241        psError(PS_ERR_UNEXPECTED_NULL, true, "Must specify an image");
     242        return NULL;
     243    }
     244    int numCols = 0, numRows = 0;       // Size of images
     245    if (image1) {
     246        PS_ASSERT_IMAGE_NON_NULL(image1, NULL);
     247        PS_ASSERT_IMAGE_TYPE(image1, PS_TYPE_F32, NULL);
     248        if (subMask) {
     249            PS_ASSERT_IMAGES_SIZE_EQUAL(image1, subMask, NULL);
     250        }
     251        numCols = image1->numCols;
     252        numRows = image1->numRows;
     253    }
     254    if (image2) {
     255        PS_ASSERT_IMAGE_NON_NULL(image2, NULL);
     256        PS_ASSERT_IMAGE_TYPE(image2, PS_TYPE_F32, NULL);
     257        if (subMask) {
     258            PS_ASSERT_IMAGES_SIZE_EQUAL(image2, subMask, NULL);
     259        }
     260        numCols = image2->numCols;
     261        numRows = image2->numRows;
     262    }
     263    if (image1 && image2) {
     264        PS_ASSERT_IMAGES_SIZE_EQUAL(image1, image2, NULL);
     265    }
    241266    if (subMask) {
    242267        PS_ASSERT_IMAGE_NON_NULL(subMask, NULL);
    243         PS_ASSERT_IMAGES_SIZE_EQUAL(image, subMask, NULL);
    244268        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_IMAGE_MASK, NULL);
     269        PS_ASSERT_IMAGE_SIZE(subMask, numCols, numRows, NULL);
    245270    }
    246271    PS_ASSERT_INT_POSITIVE(size, NULL);
     
    254279            return false;
    255280        }
    256         if (region->x0 < 0 || region->x1 > image->numCols ||
    257             region->y0 < 0 || region->y1 > image->numRows) {
     281        if (region->x0 < 0 || region->x1 > numCols ||
     282            region->y0 < 0 || region->y1 > numRows) {
    258283            psString string = psRegionToString(*region);
    259284            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Input region (%s) does not fit in image (%dx%d)",
    260                     string, image->numCols, image->numRows);
     285                    string, numCols, numRows);
    261286            psFree(string);
    262287            return false;
     
    264289    }
    265290
    266     int numRows = image->numRows, numCols = image->numCols; // Size of image
    267291    int border = size + footprint;      // Border size
    268292
     
    312336                    fluxList->n = index;
    313337
    314                     goodStamp = (fluxStamp > threshold) ? true : false;
     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                    }
    315345                } else {
    316346                    psTrace("psModules.imcombine", 9, "No sources in subregion %d", i);
     
    319349                // Use a simple method of automatically finding stamps --- take the highest pixel in the
    320350                // subregion
    321                 fluxStamp = threshold;
     351                fluxStamp = 0.0;
    322352                psRegion *subRegion = stamps->regions->data[i]; // Sub-region of interest
     353
     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
    323371                for (int y = subRegion->y0; y <= subRegion->y1; y++) {
    324372                    for (int x = subRegion->x0; x <= subRegion->x1; x++) {
    325                         if (image->data.F32[y][x] > fluxStamp &&
     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 &&
    326380                            checkStampMask(x, y, numCols, numRows, subMask, mode, footprint, border)) {
    327381                            fluxStamp = image->data.F32[y][x];
  • trunk/psModules/src/imcombine/pmSubtractionStamps.h

    r23849 r23937  
    7474/// Find stamps on an image
    7575pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, ///< Output stamps, or NULL
    76                                                 const psImage *image, ///< Image for which to find stamps
     76                                                const psImage *image1, ///< Image for which to find stamps
     77                                                const psImage *image2, ///< Image for which to find stamps
    7778                                                const psImage *mask, ///< Mask, or NULL
    7879                                                const psRegion *region, ///< Region to search, or NULL
    79                                                 float threshold, ///< Threshold for stamps in the image
     80                                                float thresh1, ///< Threshold for stamps in image 1
     81                                                float thresh2, ///< Threshold for stamps in image 2
    8082                                                int size, ///< Kernel half-size
    8183                                                int footprint, ///< Half-size for stamps
Note: See TracChangeset for help on using the changeset viewer.