Changeset 9981
- Timestamp:
- Nov 14, 2006, 2:27:52 PM (19 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
-
pmMaskBadPixels.c (modified) (2 diffs)
-
pmMaskBadPixels.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmMaskBadPixels.c
r9616 r9981 4 4 5 5 #include <stdio.h> 6 #include <math.h> 6 7 #include <pslib.h> 7 8 … … 67 68 return true; 68 69 } 70 71 72 psImage *pmMaskFlagSuspectPixels(psImage *out, const pmReadout *readout, float rej, 73 psMaskType maskVal, float frac, psRandom *rng) 74 { 75 PS_ASSERT_PTR_NON_NULL(readout, NULL); 76 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, NULL); 77 PS_ASSERT_FLOAT_WITHIN_RANGE(frac, 0.0, 1.0, NULL); 78 PS_ASSERT_IMAGE_NON_NULL(readout->image, NULL); 79 PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL); 80 PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, NULL); 81 if (readout->mask) { 82 PS_ASSERT_IMAGE_NON_EMPTY(readout->mask, NULL); 83 PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, readout->mask, NULL); 84 PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, NULL); 85 } 86 if (out) { 87 PS_ASSERT_IMAGE_NON_EMPTY(out, NULL); 88 PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_S32, NULL); 89 PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, out, NULL); 90 } 91 92 psImage *image = readout->image; // Image of interest 93 psImage *mask = readout->mask; // Corresponding mask 94 95 if (rng) { 96 psMemIncrRefCounter(rng); 97 } else { 98 rng = psRandomAlloc(PS_RANDOM_TAUS, 0); 99 } 100 101 psStats *stats = psImageBackground(image, mask, maskVal, 0.25, 0.75, 102 frac * image->numCols * image->numRows, rng); // Image statistics 103 if (!stats || !isfinite(stats->robustMedian) || !isfinite(stats->robustUQ) || 104 !isfinite(stats->robustLQ)) { 105 psError(PS_ERR_UNKNOWN, false, "Unable to measure image statistics.\n"); 106 psFree(stats); 107 psFree(rng); 108 return NULL; 109 } 110 psFree(rng); 111 112 float median = stats->robustMedian; // Median value 113 float stdev = 0.74*(stats->robustUQ - stats->robustLQ); // Estimate of the standard deviation 114 psFree(stats); 115 116 if (!out) { 117 out = psImageAlloc(image->numCols, image->numRows, PS_TYPE_S32); 118 psImageInit(out, 0); 119 } 120 121 for (int y = 0; y < image->numRows; y++) { 122 for (int x = 0; x < image->numCols; x++) { 123 if (fabs((image->data.F32[y][x] - median) / stdev) >= rej && 124 (!mask || !(mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal))) { 125 out->data.S32[y][x]++; 126 } 127 } 128 } 129 130 return out; 131 } 132 133 134 psImage *pmMaskIdentifyBadPixels(const psImage *suspects, float thresh, psMaskType maskVal) 135 { 136 PS_ASSERT_IMAGE_NON_NULL(suspects, NULL); 137 PS_ASSERT_IMAGE_NON_EMPTY(suspects, NULL); 138 PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, NULL); 139 140 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_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); 145 return NULL; 146 } 147 148 float mean = stats->sampleMean; // Mean value 149 float stdev = stats->sampleStdev; // Standard deviation 150 151 psImage *badpix = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK); // Bad pixel mask 152 psImageInit(badpix, 0); 153 154 if (psTraceGetLevel("psModules.detrend") > 9) { 155 psStats *stats = psStatsAlloc(PS_STAT_MIN | PS_STAT_MAX); // Statistics 156 psImageStats(stats, suspects, NULL, 0); 157 psHistogram *histo = psHistogramAlloc(-0.5, stats->max + 0.5, stats->max + 1); 158 psImageHistogram(histo, suspects, NULL, 0); 159 for (int i = 0; i < histo->nums->n; i++) { 160 printf("%f --> %f : %f\n", histo->bounds->data.F32[i], histo->bounds->data.F32[i + 1], 161 histo->nums->data.F32[i]); 162 } 163 psFree(stats); 164 psFree(histo); 165 printf("Threshold: %f\n", mean + thresh * stdev); 166 } 167 168 for (int y = 0; y < suspects->numRows; y++) { 169 for (int x = 0; x < suspects->numCols; x++) { 170 if (suspects->data.S32[y][x] - mean >= thresh * stdev) { 171 badpix->data.PS_TYPE_MASK_DATA[y][x] = maskVal; 172 } 173 } 174 } 175 176 return badpix; 177 } -
trunk/psModules/src/detrend/pmMaskBadPixels.h
r9616 r9981 8 8 /// @author Eugene Magnier, IfA 9 9 /// 10 /// @version $Revision: 1. 8$ $Name: not supported by cvs2svn $11 /// @date $Date: 2006-1 0-17 22:17:38$10 /// @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 11 /// @date $Date: 2006-11-15 00:27:52 $ 12 12 /// 13 13 /// Copyright 2004 Institute for Astronomy, University of Hawaii … … 33 33 ); 34 34 35 /// Find pixels outlying from the background, flagging suspect pixels 36 /// 37 /// Pixels more than "rej" standard deviations from the background level (in flat-fielded images) have the 38 /// corresponding pixel in the "suspect pixels" image incremented. After accumulating over a suitable sample 39 /// of images, bad pixels should have a high value in the suspect pixels image, allowing them to be 40 /// identified. The suspect pixels image is of type S32. 41 psImage *pmMaskFlagSuspectPixels(psImage *out, ///< Suspected bad pixels image, or NULL 42 const pmReadout *readout, ///< Readout to inspect 43 float rej, ///< Rejection threshold (standard deviations) 44 psMaskType maskVal, ///< Mask value for statistics 45 float frac, ///< Fraction of pixels to consider 46 psRandom *rng ///< Random number generator 47 ); 48 49 /// Identify bad pixels from the suspect pixels image 50 /// 51 /// Bad pixels are identified from the suspect pixels image (accumulated over a large number of images). 52 /// Pixels marked as suspect in more than "thresh" standard deviations from the mean are identified as bad 53 /// pixels (output image). 54 psImage *pmMaskIdentifyBadPixels(const psImage *suspects, ///< Accumulated suspect pixels image 55 float thresh, ///< Threshold for bad pixel (standard deviations) 56 psMaskType maskVal ///< Value to set for bad pixels 57 ); 58 59 60 61 35 62 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
