Changeset 10022 for trunk/psModules/src/detrend/pmMaskBadPixels.c
- Timestamp:
- Nov 16, 2006, 2:40:10 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmMaskBadPixels.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmMaskBadPixels.c
r10019 r10022 138 138 PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, NULL); 139 139 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); 145 175 return NULL; 146 176 } 147 148 float mean = stats->robustMedian; // Mean value149 float stdev = stats->robustStdev; // Standard deviation150 psFree(stats);151 177 152 178 psImage *badpix = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK); // Bad pixel mask … … 164 190 psFree(stats); 165 191 psFree(histo); 166 printf("Threshold: %f\n", mean + thresh * stdev);192 printf("Threshold: %f\n", limit); 167 193 } 168 194 169 195 for (int y = 0; y < suspects->numRows; y++) { 170 196 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) { 172 198 badpix->data.PS_TYPE_MASK_DATA[y][x] = maskVal; 173 199 }
Note:
See TracChangeset
for help on using the changeset viewer.
