Changeset 37811 for trunk/psModules/src/objects/pmTrend2D.c
- Timestamp:
- Jan 11, 2015, 2:57:41 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmTrend2D.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmTrend2D.c
r30044 r37811 211 211 // XXX need to add the API which adjusts the scale 212 212 status = psImageMapClipFit(pGoodFit, trend->map, trend->stats, mask, maskVal, x, y, f, df); 213 if (!status) { 214 psError(PS_ERR_UNKNOWN, true, "failed to build PSF model map"); 215 return false; 216 } 217 218 // the psf model map can have nan pixels: repair this by extrapolation / interpolation 219 // XXX TEST: p_psImagePrint(0, trend->map->map, "before"); 220 status = psImageMapRepair (trend->map->map); 221 // XXX TEST: p_psImagePrint(0, trend->map->map, "after"); 222 if (!status) { 223 psError(PS_ERR_UNKNOWN, true, "failed to repair PSF model map"); 224 return false; 225 } 213 226 break; 214 227 … … 217 230 } 218 231 return status; 232 } 233 234 bool psImageMapRepair (psImage *map) { 235 236 237 // XXX why is my repair not working?? 238 239 // patch over bad regions (use average of 8 possible neighbor pixels) 240 // XXX consider testing all pixels against the 8 neighbors and replacing outliers... 241 double Count = 0; // number of good pixels 242 double Value = 0; // sum of good pixel's value 243 for (int iy = 0; iy < map->numRows; iy++) { 244 for (int ix = 0; ix < map->numCols; ix++) { 245 if (isfinite(map->data.F32[iy][ix])) { 246 Value += map->data.F32[iy][ix]; 247 Count++; 248 continue; 249 } 250 251 double value = 0; 252 double count = 0; 253 for (int jy = iy - 1; jy <= iy + 1; jy++) { 254 if (jy < 0) continue; 255 if (jy >= map->numRows) continue; 256 for (int jx = ix - 1; jx <= ix + 1; jx++) { 257 if (!jx && !jy) continue; 258 if (jx < 0) continue; 259 if (jx >= map->numCols) continue; 260 if (!isfinite(map->data.F32[jy][jx])) continue; 261 value += map->data.F32[jy][jx]; 262 count += 1.0; 263 } 264 } 265 if (count > 0) { 266 // psLogMsg ("psphot", PS_LOG_DETAIL, "patching image map %d, %d: %f (%d pts)\n", ix, iy, (value / count), (int) count); 267 map->data.F32[iy][ix] = value / count; 268 } 269 } 270 } 271 if (Count == 0) { 272 psError(PS_ERR_UNKNOWN, true, "failed to repair PSF model map"); 273 return false; 274 } 275 Value /= Count; 276 277 // patch over remaining bad regions (use global average) 278 for (int iy = 0; iy < map->numRows; iy++) { 279 for (int ix = 0; ix < map->numCols; ix++) { 280 if (!isnan(map->data.F32[iy][ix])) continue; 281 map->data.F32[iy][ix] = Value; 282 } 283 } 284 return true; 219 285 } 220 286
Note:
See TracChangeset
for help on using the changeset viewer.
