IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2009, 1:59:32 PM (17 years ago)
Author:
beaumont
Message:

merged with trunk

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/psModules

  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionMatch.c

    r23351 r24244  
    1818#include "pmSubtractionMask.h"
    1919#include "pmSubtractionThreads.h"
     20#include "pmSubtractionVisual.h"
     21#include "pmErrorCodes.h"
     22
    2023#include "pmSubtractionMatch.h"
    21 #include "pmSubtractionVisual.h"
    2224
    2325#define BG_STAT PS_STAT_ROBUST_MEDIAN   // Statistic to use for background
     
    6264                      psImage *variance,  // Variance map
    6365                      const psRegion *region, // Region of interest, or NULL
    64                       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
    6568                      float stampSpacing, // Spacing between stamps
    6669                      int size,         // Kernel half-size
     
    7073{
    7174    psTrace("psModules.imcombine", 3, "Finding stamps...\n");
    72     *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, footprint,
    73                                       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);
    7480    if (!*stamps) {
    75         psError(PS_ERR_UNKNOWN, false, "Unable to find stamps.");
     81        psError(psErrorCodeLast(), false, "Unable to find stamps.");
    7682        return false;
    7783    }
     
    238244
    239245    psImage *subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, 0,
    240                                          badFrac, useFFT); // Subtraction mask
     246                                         badFrac, mode); // Subtraction mask
    241247    if (!subMask) {
    242248        psError(PS_ERR_UNKNOWN, false, "Unable to generate subtraction mask.");
     
    371377
    372378    subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, footprint,
    373                                 badFrac, useFFT);
     379                                badFrac, subMode);
    374380    if (!subMask) {
    375381        psError(PS_ERR_UNKNOWN, false, "Unable to generate subtraction mask.");
     
    390396    }
    391397
     398    float stampThresh1 = NAN, stampThresh2 = NAN; // Stamp thresholds for images
    392399    {
    393400        psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for backgroun
    394         if (!psImageBackground(bg, NULL, ro1->image, ro1->mask, maskVal, rng)) {
    395             psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
    396             psFree(bg);
    397             psFree(rng);
    398             goto MATCH_ERROR;
    399         }
    400         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                goto MATCH_ERROR;
     406            }
     407            stampThresh1 = bg->robustMedian + threshold * bg->robustStdev;
     408        }
     409        if (ro2) {
     410            if (!psImageBackground(bg, NULL, ro2->image, ro2->mask, maskVal, rng)) {
     411                psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
     412                psFree(bg);
     413                goto MATCH_ERROR;
     414            }
     415            stampThresh2 = bg->robustMedian + threshold * bg->robustStdev;
     416        }
    401417        psFree(bg);
    402418    }
     
    416432            }
    417433
    418             if (sources) {
    419                 stamps = pmSubtractionStampsSetFromSources(sources, ro1->image, subMask, region, footprint,
    420                                                           stampSpacing, subMode);
    421             } else if (stampsName && strlen(stampsName) > 0) {
    422                 stamps = pmSubtractionStampsSetFromFile(stampsName, ro1->image, subMask, region, footprint,
    423                                                         stampSpacing, subMode);
     434            if (stampsName && strlen(stampsName) > 0) {
     435                stamps = pmSubtractionStampsSetFromFile(stampsName, ro1->image, subMask, region, size,
     436                                                        footprint, stampSpacing, subMode);
     437            } else if (sources) {
     438                stamps = pmSubtractionStampsSetFromSources(sources, ro1->image, subMask, region, size,
     439                                                           footprint, stampSpacing, subMode);
    424440            }
    425441
    426442            // We get the stamps here; we will also attempt to get stamps at the first iteration, but it
    427443            // doesn't matter.
    428             if (!getStamps(&stamps, ro1, ro2, subMask, variance, NULL, threshold, stampSpacing,
    429                            size, footprint, subMode)) {
     444            if (!getStamps(&stamps, ro1, ro2, subMask, variance, NULL, stampThresh1, stampThresh2,
     445                           stampSpacing, size, footprint, subMode)) {
    430446                goto MATCH_ERROR;
    431447            }
     
    488504                psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k);
    489505
    490                 if (!getStamps(&stamps, ro1, ro2, subMask, variance, region, threshold, stampSpacing,
    491                                size, footprint, subMode)) {
     506                if (!getStamps(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2,
     507                               stampSpacing, size, footprint, subMode)) {
    492508                    goto MATCH_ERROR;
    493509                }
     
    565581            psFree(kernels);
    566582            kernels = NULL;
    567 
    568             // There is data in the readout now
    569             if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_DUAL) {
    570                 conv1->data_exists = true;
    571                 if (conv1->parent) {
    572                     conv1->parent->data_exists = true;
    573                     conv1->parent->parent->data_exists = true;
    574                 }
    575             }
    576             if (subMode == PM_SUBTRACTION_MODE_2 || subMode == PM_SUBTRACTION_MODE_DUAL) {
    577                 conv2->data_exists = true;
    578                 if (conv2->parent) {
    579                     conv2->parent->data_exists = true;
    580                     conv2->parent->parent->data_exists = true;
    581                 }
    582             }
    583583        }
    584584    }
     
    830830    psFree(mask);
    831831
     832    // XXX raise an error here or not?
     833    if (isnan(stats->robustMedian)) {
     834        psFree(stats);
     835        return PM_SUBTRACTION_MODE_ERR;
     836    }
     837
    832838    psLogMsg("psModules.imcombine", PS_LOG_INFO, "Median width ratio: %lf", stats->robustMedian);
    833839    pmSubtractionMode mode = (stats->robustMedian <= 1.0 ? PM_SUBTRACTION_MODE_1 : PM_SUBTRACTION_MODE_2);
    834840    psFree(stats);
    835841
    836     // XXX EAM : I think Paul left some test code in here.  I've commented these lines out
    837     // return PM_SUBTRACTION_MODE_2;
    838     // exit(1);
    839 
    840842    return mode;
    841843}
Note: See TracChangeset for help on using the changeset viewer.