IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20622


Ignore:
Timestamp:
Nov 9, 2008, 8:32:10 PM (18 years ago)
Author:
Paul Price
Message:

Another different algorithm: sum over the column in stages and compare with the background stdev.

Location:
trunk/psModules/src/detrend
Files:
2 edited

Legend:

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

    r20621 r20622  
    1010
    1111#define SIZE 30                         // Size of accumulation patch
    12 
    13 #define THRESHOLD 4.0                   // Threshold above background
    14 
     12#define THRESHOLD 20.0                   // Threshold above background
    1513
    1614bool pmRemnance(pmReadout *ro,           ///< Readout with input image
    1715                psMaskType maskVal,      ///< Value of mask
    18                 psMaskType maskRem       ///< Value to give remance
     16                psMaskType maskRem,       ///< Value to give remance
     17                int size,               ///< Size of accumulation patches
     18                float threshold         ///< Threshold for masking
    1919    )
    2020{
     
    3636    }
    3737    psFree(rng);
    38     float bg = stats->robustMedian;     // Background level
     38    float bgMean = stats->robustMedian; // Background level
     39    float bgStdev = stats->robustStdev; // Background stdev
    3940
    40     // Starting at the bottom of the detector, mask pixels that are significant
    41     psVector *colSums = psVectorAlloc(numCols, PS_TYPE_F32); // Sums for each column
    42     psVectorInit(colSums, 0.0);
    43     psVector *colNums = psVectorAlloc(numCols, PS_TYPE_S32); // Number for each column
    44     psVectorInit(colNums, 0);
    45     psVector *colAvgs = psVectorAlloc(numCols, PS_TYPE_F32); // Average for each column
    46     psVector *colMask = psVectorAlloc(numCols, PS_TYPE_MASK); // Mask for each column
     41    stats->options = PS_STAT_SAMPLE_MEDIAN;
     42
    4743    int numMasked = 0;                  // Number of pixels masked
    48     int numAccumulations = ceil(numRows / (float)SIZE); // Number of accumulations up the columns
    49     for (int i = 0; i < numAccumulations; i++) {
    50         int min = i * SIZE;             // Minimum coordinate
    51         int max = PS_MIN(min + SIZE, numRows); // Maximum coordinate
    52         for (int x = 0; x < numCols; x++) {
    53             int num = 0;                // Number of pixels in accumulation
    54             float sum = 0.0;            // Sum of pixels in accumulation
     44    int number = ceil(numRows / (float)SIZE); // Number of steps up the columns
     45    psVector *values = psVectorAlloc(numRows, PS_TYPE_F32); // Values below center
     46    for (int x = 0; x < numCols; x++) {
     47        int maxMask = 0;                // Maximum row to which to mask
     48        int numValues = 0;              // Number of values
     49        for (int i = 0, min = 0, max = size; i < number; i++, min += size, max += size) {
     50
     51            if (max > numRows) {
     52                max = numRows;
     53            }
    5554            for (int y = min; y < max; y++) {
    5655                if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
    5756                    continue;
    5857                }
    59                 sum += image->data.F32[y][x] - bg;
    60                 num++;
     58                values->data.F32[numValues++] = image->data.F32[y][x];
    6159            }
    62             colSums->data.F32[x] = sum;
    63             colNums->data.S32[x] = num;
    64             colAvgs->data.F32[x] = sum / (float)num;
    65             colMask->data.PS_TYPE_MASK_DATA[x] = (colNums->data.S32[x] == 0 ? 0xFF : 0);
     60            values->n = numValues;
     61            if (!psVectorStats(stats, values, NULL, NULL, 0)) {
     62                // Can't do anything about it
     63                psErrorClear();
     64                maxMask = max;
     65                continue;
     66            }
     67            float median = stats->sampleMedian;
     68
     69            if (median > bgMean + threshold * bgStdev / sqrtf(numValues)) {
     70                maxMask = max;
     71            }
    6672        }
    6773
    68         if (!psVectorStats(stats, colAvgs, NULL, colMask, 0xFF)) {
    69             psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on column accumulations.");
    70             psFree(colSums);
    71             psFree(colNums);
    72             psFree(colAvgs);
    73             psFree(colMask);
    74             psFree(stats);
    75             return false;
     74        maxMask += size;
     75        if (maxMask > numRows) {
     76            maxMask = numRows;
    7677        }
     78        for (int y = 0; y < maxMask; y++) {
     79            mask->data.PS_TYPE_MASK_DATA[y][x] |= maskRem;
     80        }
     81        numMasked += maxMask;
    7782
    78         float threshold = stats->robustMedian + THRESHOLD * stats->robustStdev; // Threshold for masking
    79 
    80         max = PS_MIN(max + SIZE, numRows);
    81 
    82         for (int x = 0; x < numCols; x++) {
    83             if (colAvgs->data.F32[x] > threshold) {
    84                 for (int y = 0; y < max; y++) {
    85                     mask->data.PS_TYPE_MASK_DATA[y][x] = maskRem;
    86                     numMasked++;
    87                 }
    88             }
    89         }
    9083    }
    91 
    92     psFree(colSums);
    93     psFree(colNums);
    94     psFree(colAvgs);
    95     psFree(colMask);
     84    psFree(values);
    9685    psFree(stats);
    9786
  • trunk/psModules/src/detrend/pmRemnance.h

    r20620 r20622  
    1414bool pmRemnance(pmReadout *ro,           ///< Readout with input image
    1515                psMaskType maskVal,      ///< Value of mask
    16                 psMaskType maskRem       ///< Value to give remance
     16                psMaskType maskRem,       ///< Value to give remance
     17                int size,               ///< Size of accumulation patches
     18                float threshold         ///< Threshold for masking
    1719    );
    1820
    19 
    2021#endif
Note: See TracChangeset for help on using the changeset viewer.