IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 22, 2009, 5:13:36 PM (17 years ago)
Author:
Paul Price
Message:

Fixing pattern subtraction so that it ignores pixels away from the median, in order to reduce bad subtractions around bright stars. Changed API for pmPatternRow, added new recipe paramter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmPattern.c

    r24899 r24903  
    3030}
    3131
    32 bool pmPatternRow(pmReadout *ro, int order, int iter, float rej,
     32bool pmPatternRow(pmReadout *ro, int order, int iter, float rej, float thresh,
    3333                  psStatsOptions clipMean, psStatsOptions clipStdev,
    34                   psImageMaskType maskBad)
     34                  psImageMaskType maskVal, psImageMaskType maskBad)
    3535{
    3636    PM_ASSERT_READOUT_NON_NULL(ro, false);
     
    3939    PS_ASSERT_INT_NONNEGATIVE(iter, false);
    4040    PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false);
     41    PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, false);
    4142
    4243    psImage *image = ro->image;         // Image to correct
     44    psImage *mask = ro->mask;           // Mask for image
    4345    int numCols = image->numCols, numRows = image->numRows; // Size of image
     46
     47    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     48    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
     49    if (!psImageBackground(stats, NULL, ro->image, ro->mask, maskVal, rng)) {
     50        psWarning("Unable to calculate statistics on readout.");
     51        psFree(stats);
     52        psFree(rng);
     53        return false;
     54    }
     55    float lower = stats->robustMedian - thresh * stats->robustStdev; // Lower bound for data
     56    float upper = stats->robustMedian + thresh * stats->robustStdev; // Upper bound for data
     57    psFree(stats);
     58    psFree(rng);
    4459
    4560    // Indices are distributed [-1:1)
     
    5368    clip->clipIter = iter;
    5469    clip->clipSigma = rej;
    55     psVector *mask = psVectorAlloc(numCols, PS_TYPE_VECTOR_MASK); // Mask for fitting
     70    psVector *clipMask = psVectorAlloc(numCols, PS_TYPE_VECTOR_MASK); // Mask for clipping
    5671    psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, order); // Polynomial to fit
    5772    psVector *data = psVectorAlloc(numCols, PS_TYPE_F32); // Data to fit
    5873
    5974    for (int y = 0; y < numRows; y++) {
    60         psVectorInit(mask, 0);
     75        psVectorInit(clipMask, 0);
    6176        data = psImageRow(data, image, y);
    6277        int num = 0;                    // Number of good pixels
    6378        for (int x = 0; x < numCols; x++) {
    64             if (ro->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] > 0) {
    65                 mask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0xFF;
     79            if ((mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) ||
     80                data->data.F32[x] < lower || data->data.F32[x] > upper) {
     81                clipMask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0xFF;
    6682            } else {
    67                 mask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0;
     83                clipMask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0;
    6884                num++;
    6985            }
     
    7490            continue;
    7591        }
    76         if (!psVectorClipFitPolynomial1D(poly, clip, mask, 0xFF, data, NULL, indices)) {
     92        if (!psVectorClipFitPolynomial1D(poly, clip, clipMask, 0xFF, data, NULL, indices)) {
    7793            psWarning("Unable to fit polynomial to row %d", y);
    7894            psErrorClear();
     
    96112    psFree(indices);
    97113    psFree(clip);
    98     psFree(mask);
     114    psFree(clipMask);
    99115    psFree(poly);
    100116    psFree(data);
Note: See TracChangeset for help on using the changeset viewer.