IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 16, 2006, 2:40:10 PM (20 years ago)
Author:
Paul Price
Message:

Adding additional option for identifying bad pixels.

File:
1 edited

Legend:

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

    r10019 r10022  
    138138    PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, NULL);
    139139
    140     psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics
    141     if (!psImageStats(stats, suspects, NULL, 0) || !isfinite(stats->sampleMean) ||
    142             !isfinite(stats->sampleStdev)) {
    143         psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics.\n");
    144         psFree(stats);
     140    float limit = NAN;                  // Limit for masking
     141    if (thresh > 0) {
     142        psStats *stats = psStatsAlloc(PS_STAT_CLIPPED_STDEV); // Statistics
     143        stats->clipSigma = 5.0;
     144        stats->clipIter = 1;
     145        if (!psImageStats(stats, suspects, NULL, 0) || !isfinite(stats->clippedStdev)) {
     146            psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics.\n");
     147            psFree(stats);
     148            return NULL;
     149        }
     150        limit = thresh * stats->clippedStdev;
     151        psFree(stats);
     152    } else if (thresh < 0) {
     153        psStats *stats = psStatsAlloc(PS_STAT_MAX); // Statistics
     154        if (!psImageStats(stats, suspects, NULL, 0)) {
     155            psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics.\n");
     156            psFree(stats);
     157            return NULL;
     158        }
     159        psHistogram *histo = psHistogramAlloc(-0.5, stats->max + 0.5, stats->max + 1);
     160        psFree(stats);
     161        if (!psImageHistogram(histo, suspects, NULL, 0)) {
     162            psError(PS_ERR_UNKNOWN, false, "Unable to generate histogram.\n");
     163            psFree(histo);
     164            return NULL;
     165        }
     166
     167        float target = histo->nums->data.F32[0] * powf(10.0, thresh); // Level to which histogram must fall
     168        int index;
     169        for (index = 0; histo->nums->data.F32[index] > target && index < histo->nums->n; index++)
     170            ;
     171        limit = histo->bounds->data.F32[index];
     172    } else {
     173        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     174                "Threshold (%f) must be a positive or negative real number.\n", thresh);
    145175        return NULL;
    146176    }
    147 
    148     float mean = stats->robustMedian;     // Mean value
    149     float stdev = stats->robustStdev;   // Standard deviation
    150     psFree(stats);
    151177
    152178    psImage *badpix = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK); // Bad pixel mask
     
    164190        psFree(stats);
    165191        psFree(histo);
    166         printf("Threshold: %f\n", mean + thresh * stdev);
     192        printf("Threshold: %f\n", limit);
    167193    }
    168194
    169195    for (int y = 0; y < suspects->numRows; y++) {
    170196        for (int x = 0; x < suspects->numCols; x++) {
    171             if (suspects->data.S32[y][x] - mean >= thresh * stdev) {
     197            if (suspects->data.S32[y][x] >= limit) {
    172198                badpix->data.PS_TYPE_MASK_DATA[y][x] = maskVal;
    173199            }
Note: See TracChangeset for help on using the changeset viewer.