Changeset 24903 for trunk/psModules/src/detrend/pmPattern.c
- Timestamp:
- Jul 22, 2009, 5:13:36 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmPattern.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmPattern.c
r24899 r24903 30 30 } 31 31 32 bool pmPatternRow(pmReadout *ro, int order, int iter, float rej, 32 bool pmPatternRow(pmReadout *ro, int order, int iter, float rej, float thresh, 33 33 psStatsOptions clipMean, psStatsOptions clipStdev, 34 psImageMaskType mask Bad)34 psImageMaskType maskVal, psImageMaskType maskBad) 35 35 { 36 36 PM_ASSERT_READOUT_NON_NULL(ro, false); … … 39 39 PS_ASSERT_INT_NONNEGATIVE(iter, false); 40 40 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false); 41 PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, false); 41 42 42 43 psImage *image = ro->image; // Image to correct 44 psImage *mask = ro->mask; // Mask for image 43 45 int numCols = image->numCols, numRows = image->numRows; // Size of image 46 47 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 48 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 49 if (!psImageBackground(stats, NULL, ro->image, ro->mask, maskVal, rng)) { 50 psWarning("Unable to calculate statistics on readout."); 51 psFree(stats); 52 psFree(rng); 53 return false; 54 } 55 float lower = stats->robustMedian - thresh * stats->robustStdev; // Lower bound for data 56 float upper = stats->robustMedian + thresh * stats->robustStdev; // Upper bound for data 57 psFree(stats); 58 psFree(rng); 44 59 45 60 // Indices are distributed [-1:1) … … 53 68 clip->clipIter = iter; 54 69 clip->clipSigma = rej; 55 psVector * mask = psVectorAlloc(numCols, PS_TYPE_VECTOR_MASK); // Mask for fitting70 psVector *clipMask = psVectorAlloc(numCols, PS_TYPE_VECTOR_MASK); // Mask for clipping 56 71 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, order); // Polynomial to fit 57 72 psVector *data = psVectorAlloc(numCols, PS_TYPE_F32); // Data to fit 58 73 59 74 for (int y = 0; y < numRows; y++) { 60 psVectorInit( mask, 0);75 psVectorInit(clipMask, 0); 61 76 data = psImageRow(data, image, y); 62 77 int num = 0; // Number of good pixels 63 78 for (int x = 0; x < numCols; x++) { 64 if (ro->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] > 0) { 65 mask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0xFF; 79 if ((mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) || 80 data->data.F32[x] < lower || data->data.F32[x] > upper) { 81 clipMask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0xFF; 66 82 } else { 67 mask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0;83 clipMask->data.PS_TYPE_VECTOR_MASK_DATA[x] = 0; 68 84 num++; 69 85 } … … 74 90 continue; 75 91 } 76 if (!psVectorClipFitPolynomial1D(poly, clip, mask, 0xFF, data, NULL, indices)) {92 if (!psVectorClipFitPolynomial1D(poly, clip, clipMask, 0xFF, data, NULL, indices)) { 77 93 psWarning("Unable to fit polynomial to row %d", y); 78 94 psErrorClear(); … … 96 112 psFree(indices); 97 113 psFree(clip); 98 psFree( mask);114 psFree(clipMask); 99 115 psFree(poly); 100 116 psFree(data);
Note:
See TracChangeset
for help on using the changeset viewer.
