Changeset 17228 for trunk/psModules/src/detrend/pmMaskBadPixels.c
- Timestamp:
- Mar 28, 2008, 5:10:17 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/detrend/pmMaskBadPixels.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmMaskBadPixels.c
r16413 r17228 81 81 82 82 83 psImage *pmMaskFlagSuspectPixels(psImage *out, const pmReadout *readout, float rej,84 psMaskType maskVal)83 bool pmMaskFlagSuspectPixels(pmReadout *output, const pmReadout *readout, float median, float stdev, 84 float rej, psMaskType maskVal) 85 85 { 86 PS_ASSERT_PTR_NON_NULL(readout, NULL);87 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, NULL);88 PS_ASSERT_IMAGE_NON_NULL(readout->image, NULL);89 PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL);90 PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, NULL);86 PS_ASSERT_PTR_NON_NULL(readout, false); 87 PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false); 88 PS_ASSERT_IMAGE_NON_NULL(readout->image, false); 89 PS_ASSERT_IMAGE_NON_EMPTY(readout->image, false); 90 PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, false); 91 91 if (readout->mask) { 92 PS_ASSERT_IMAGE_NON_EMPTY(readout->mask, NULL); 93 PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, readout->mask, NULL); 94 PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, NULL); 95 } 96 if (out) { 97 PS_ASSERT_IMAGE_NON_EMPTY(out, NULL); 98 PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_S32, NULL); 99 PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, out, NULL); 100 } 101 102 bool status; 92 PS_ASSERT_IMAGE_NON_EMPTY(readout->mask, false); 93 PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, readout->mask, false); 94 PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, false); 95 } 96 PS_ASSERT_PTR_NON_NULL(output, false); 97 98 bool mdok; // Status of MD lookup 99 psImage *suspect = psMetadataLookupPtr(&mdok, output->analysis, PM_MASK_ANALYSIS_SUSPECT); // Suspect img 100 if (suspect) { 101 PS_ASSERT_IMAGE_NON_EMPTY(suspect, false); 102 PS_ASSERT_IMAGE_TYPE(suspect, PS_TYPE_S32, false); 103 PS_ASSERT_IMAGES_SIZE_EQUAL(readout->image, suspect, false); 104 psMemIncrRefCounter(suspect); 105 } else { 106 suspect = psImageAlloc(readout->image->numCols, readout->image->numRows, PS_TYPE_S32); 107 psImageInit(suspect, 0); 108 psMetadataAddImage(output->analysis, PS_LIST_TAIL, PM_MASK_ANALYSIS_SUSPECT, PS_META_REPLACE, 109 "Suspect pixels", suspect); 110 psMetadataAddS32(output->analysis, PS_LIST_TAIL, PM_MASK_ANALYSIS_NUM, PS_META_REPLACE, 111 "Number of input images", 0); 112 } 113 114 if (!isfinite(median) || !isfinite(stdev)) { 115 // If we get down here and the statistics are missing, then we should go and mask the entire image 116 psWarning("Missing statistics --- flagging entire image as suspect."); 117 return (psImage*)psBinaryOp(suspect, suspect, "+", psScalarAlloc(1.0, PS_TYPE_S32)); 118 } 119 103 120 psImage *image = readout->image; // Image of interest 104 121 psImage *mask = readout->mask; // Corresponding mask 105 122 106 if (!out) {107 out = psImageAlloc(image->numCols, image->numRows, PS_TYPE_S32);108 psImageInit(out, 0);109 }110 111 bool whole = false; // Mask whole image?112 float median = psMetadataLookupF32 (&status, readout->analysis, "READOUT.MEDIAN");113 if (!status || !isfinite(median)) {114 whole = true;115 }116 float stdev = psMetadataLookupF32 (&status, readout->analysis, "READOUT.STDEV");117 if (!status || !isfinite(stdev)) {118 whole = true;119 }120 121 122 123 psTrace ("psModules.detrend", 3, "suspect: %f +/- %f\n", median, stdev); 123 124 if (whole) {125 // If we get down here and the statistics are missing, then we should go and mask the entire image126 psWarning("Missing statistics --- flagging entire image as suspect.");127 return (psImage*)psBinaryOp(out, out, "+", psScalarAlloc(1.0, PS_TYPE_S32));128 }129 124 130 125 for (int y = 0; y < image->numRows; y++) { … … 132 127 if (fabs((image->data.F32[y][x] - median) / stdev) >= rej && 133 128 (!mask || !(mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal))) { 134 out->data.S32[y][x]++; 135 } 136 } 137 } 138 139 return out; 140 } 141 142 psImage *pmMaskIdentifyBadPixels(const psImage *suspects, psMaskType maskVal, int nTotal, float thresh, pmMaskIdentifyMode mode) 129 suspect->data.S32[y][x]++; 130 } 131 } 132 } 133 psFree(suspect); // Drop reference 134 135 psMetadataItem *numItem = psMetadataLookup(output->analysis, PM_MASK_ANALYSIS_NUM); // Item with number 136 assert(numItem); 137 numItem->data.S32++; 138 139 return true; 140 } 141 142 bool pmMaskIdentifyBadPixels(pmReadout *output, psMaskType maskVal, float thresh, pmMaskIdentifyMode mode) 143 143 { 144 PS_ASSERT_IMAGE_NON_NULL(suspects, NULL); 145 PS_ASSERT_IMAGE_NON_EMPTY(suspects, NULL); 146 PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, NULL); 144 PS_ASSERT_PTR_NON_NULL(output, false); 145 psImage *suspects = psMetadataLookupPtr(NULL, output->analysis, PM_MASK_ANALYSIS_SUSPECT); // Suspect img 146 if (!suspects) { 147 psError(PS_ERR_UNKNOWN, false, "Unable to find image with suspected bad pixels."); 148 return false; 149 } 150 PS_ASSERT_IMAGE_NON_EMPTY(suspects, false); 151 PS_ASSERT_IMAGE_TYPE(suspects, PS_TYPE_S32, false); 152 if (output->mask) { 153 PS_ASSERT_IMAGE_NON_EMPTY(output->mask, false); 154 PS_ASSERT_IMAGES_SIZE_EQUAL(output->mask, suspects, false); 155 PS_ASSERT_IMAGE_TYPE(output->mask, PS_TYPE_MASK, false); 156 } else { 157 output->mask = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK); 158 } 159 int num = psMetadataLookupS32(NULL, output->analysis, PM_MASK_ANALYSIS_NUM); // Number of inputs 160 PS_ASSERT_INT_POSITIVE(num, false); 147 161 148 162 float limit = NAN; // Limit for masking 149 150 163 switch (mode) { 151 164 case PM_MASK_ID_VALUE: … … 154 167 155 168 case PM_MASK_ID_FRACTION: 156 limit = thresh * n Total;169 limit = thresh * num; 157 170 break; 158 171 … … 200 213 limit = max + 1.0 - thresh * sqrtf((float)max + 1.0); 201 214 202 psTrace ("psModules.detrend", 3, "bad: mode: %d, stdev: %f, limit: %f\n", max, sqrtf((float)max + 1.0), limit); 215 psTrace ("psModules.detrend", 3, "bad: mode: %d, stdev: %f, limit: %f\n", 216 max, sqrtf((float)max + 1.0), limit); 203 217 break; 204 218 } … … 207 221 return NULL; 208 222 } 209 210 psImage *badpix = psImageAlloc(suspects->numCols, suspects->numRows, PS_TYPE_MASK); // Bad pixel mask211 psImageInit(badpix, 0);212 223 213 224 if (psTraceGetLevel("psModules.detrend") > 9) { … … 227 238 psTrace ("psModules.detrend", 3, "bad pixel threshold: %f", limit); 228 239 240 psImage *badpix = output->mask; // Bad pixel mask 241 psImageInit(badpix, 0); 242 229 243 for (int y = 0; y < suspects->numRows; y++) { 230 244 for (int x = 0; x < suspects->numCols; x++) { … … 235 249 } 236 250 237 return badpix;251 return true; 238 252 } 239 253 240 254 pmMaskIdentifyMode pmMaskIdentifyModeFromString (const char *string) { 241 255 242 if (!strcasecmp (string, "VALUE")) {256 if (!strcasecmp(string, "VALUE")) { 243 257 return PM_MASK_ID_VALUE; 244 258 } 245 if (!strcasecmp (string, "FRACTION")) {259 if (!strcasecmp(string, "FRACTION")) { 246 260 return PM_MASK_ID_FRACTION; 247 261 } 248 if (!strcasecmp (string, "SIGMA")) {262 if (!strcasecmp(string, "SIGMA")) { 249 263 return PM_MASK_ID_SIGMA; 250 264 } 251 if (!strcasecmp (string, "POISSON")) {265 if (!strcasecmp(string, "POISSON")) { 252 266 return PM_MASK_ID_POISSON; 253 267 }
Note:
See TracChangeset
for help on using the changeset viewer.
