IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 21, 2008, 3:54:17 PM (18 years ago)
Author:
Paul Price
Message:

More robust estimation of mean, standard deviation.

File:
1 edited

Legend:

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

    r18287 r18652  
    2727
    2828#define PIXEL_LIST_BUFFER 100           // Number of entries to add to pixel list at a time
    29 
     29#define MIN_SAMPLE_STATS    7           // Minimum number to use sample statistics; otherwise use quartiles
    3030
    3131//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    513513    // with large N.  Therefore, let's just treat this as a Gaussian distribution.
    514514
    515     double mean = 0.0;                  // Mean deviation
    516515    int numStamps = 0;                  // Number of used stamps
     516    psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_MASK); // Mask, for statistics
     517    psVectorInit(mask, 0);
    517518    for (int i = 0; i < stamps->num; i++) {
    518519        pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
    519520        if (stamp->status != PM_SUBTRACTION_STAMP_USED) {
     521            mask->data.PS_TYPE_MASK_DATA[i] = 0xff;
    520522            continue;
    521523        }
    522         mean += deviations->data.F32[i];
    523524        numStamps++;
    524525    }
    525     mean /= numStamps;
    526 
    527     double rms = 0.0;                   // Standard deviation
    528     for (int i = 0; i < stamps->num; i++) {
    529         pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest
    530         if (stamp->status != PM_SUBTRACTION_STAMP_USED) {
    531             continue;
    532         }
    533         rms += PS_SQR(deviations->data.F32[i] - mean);
    534     }
    535     rms = sqrt(rms / (numStamps - 1));
     526    psTrace("psModules.imcombine", 1, "Number of good stamps: %d\n", numStamps);
     527
     528    if (numStamps == 0) {
     529        psError(PS_ERR_UNKNOWN, true, "No good stamps found.");
     530        psFree(mask);
     531        return -1;
     532    }
     533
     534    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV |
     535                                  PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE); // Statistics for deviatns
     536    if (!psVectorStats(stats, deviations, NULL, mask, 0xff)) {
     537        psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for deviations.");
     538        psFree(stats);
     539        psFree(mask);
     540        return -1;
     541    }
     542    psFree(mask);
     543
     544    double mean, rms;                 // Mean and RMS of deviations
     545    if (numStamps < MIN_SAMPLE_STATS) {
     546        mean = stats->sampleMean;
     547        rms = stats->sampleStdev;
     548    } else {
     549        mean = stats->sampleMedian;
     550        rms = 0.74 * (stats->sampleUQ - stats->sampleLQ);
     551    }
     552
     553    psTrace("psModules.imcombine", 1, "Mean: %f\n", mean);
     554    psTrace("psModules.imcombine", 1, "RMS deviation: %f\n", rms);
    536555
    537556    if (rmsPtr) {
     
    540559    if (numPtr) {
    541560        *numPtr = numStamps;
    542     }
    543 
    544     if (numStamps == 0) {
    545         psError(PS_ERR_UNKNOWN, true, "No good stamps found.");
    546         return -1;
    547561    }
    548562
Note: See TracChangeset for help on using the changeset viewer.