IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28301


Ignore:
Timestamp:
Jun 10, 2010, 4:18:42 PM (16 years ago)
Author:
Paul Price
Message:

Be more careful about measuring mean variance --- with a small number of values, robust median can fail. Borrowed this code from psFitsScale.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackTarget.c

    r28256 r28301  
    164164
    165165        psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for background
     166        float mean = NAN;                                  // Measured mean variance
    166167        if (!psImageBackground(bg, NULL, variance, mask, maskVal, rng)) {
    167             psError(PPSTACK_ERR_DATA, false, "Can't measure background for image.");
    168             psFree(rng);
    169             return NULL;
     168            psErrorClear();
     169            // Retry using all the available pixels
     170            bg->nSubsample = variance->numCols * variance->numRows + 1;
     171            if (!psImageStats(bg, variance, mask, maskVal)) {
     172                psLogMsg("ppStack", PS_LOG_DETAIL,
     173                         "Couldn't measure mean variance for image %d; retrying.", i);
     174                psErrorClear();
     175                // Retry with desperate statistic
     176                bg->options = PS_STAT_SAMPLE_MEAN;
     177                if (!psImageStats(bg, variance, mask, maskVal)) {
     178                    psError(PPSTACK_ERR_DATA, false, "Unable to measure mean variance for image %d", i);
     179                    psFree(rng);
     180                    psFree(bg);
     181                    return NULL;
     182                } else {
     183                    // Desperate retry
     184                    mean = bg->sampleMean;
     185                }
     186            } else {
     187                // Retry with all available pixels
     188                mean = bg->robustMedian;
     189            }
     190        } else {
     191            // First attempt
     192            mean = bg->robustMedian;
    170193        }
    171194
Note: See TracChangeset for help on using the changeset viewer.