Changeset 20622
- Timestamp:
- Nov 9, 2008, 8:32:10 PM (18 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
-
pmRemnance.c (modified) (2 diffs)
-
pmRemnance.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmRemnance.c
r20621 r20622 10 10 11 11 #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 15 13 16 14 bool pmRemnance(pmReadout *ro, ///< Readout with input image 17 15 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 19 19 ) 20 20 { … … 36 36 } 37 37 psFree(rng); 38 float bg = stats->robustMedian; // Background level 38 float bgMean = stats->robustMedian; // Background level 39 float bgStdev = stats->robustStdev; // Background stdev 39 40 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 47 43 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 } 55 54 for (int y = min; y < max; y++) { 56 55 if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) { 57 56 continue; 58 57 } 59 sum += image->data.F32[y][x] - bg; 60 num++; 58 values->data.F32[numValues++] = image->data.F32[y][x]; 61 59 } 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 } 66 72 } 67 73 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; 76 77 } 78 for (int y = 0; y < maxMask; y++) { 79 mask->data.PS_TYPE_MASK_DATA[y][x] |= maskRem; 80 } 81 numMasked += maxMask; 77 82 78 float threshold = stats->robustMedian + THRESHOLD * stats->robustStdev; // Threshold for masking79 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 }90 83 } 91 92 psFree(colSums); 93 psFree(colNums); 94 psFree(colAvgs); 95 psFree(colMask); 84 psFree(values); 96 85 psFree(stats); 97 86 -
trunk/psModules/src/detrend/pmRemnance.h
r20620 r20622 14 14 bool pmRemnance(pmReadout *ro, ///< Readout with input image 15 15 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 17 19 ); 18 20 19 20 21 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
