Changeset 10553
- Timestamp:
- Dec 8, 2006, 1:54:05 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotImageMedian.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotImageMedian.c
r10437 r10553 40 40 } 41 41 psStatsOptions statsOption = psStatsOptionFromString (statsName); 42 if (!(statsOption & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN ))) {42 if (!(statsOption & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN | PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE | PS_STAT_CLIPPED_MEAN | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_MEAN_V2))) { 43 43 statsOption = PS_STAT_FITTED_MEAN; 44 44 } … … 141 141 stats->options |= PS_STAT_ROBUST_MEDIAN; 142 142 if (!psImageBackground(stats, subset, submask, 0xff, rng)) { 143 psAbort(PS_FILE_LINE, "Failed to estimate background using ROBUST_MEDIAN for " 144 "(%dx%d, (row0,col0) = (%d,%d)", 145 subset->numRows, subset->numCols, subset->row0, subset->col0); 143 psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for " 144 "(%dx%d, (row0,col0) = (%d,%d)", 145 subset->numRows, subset->numCols, subset->row0, subset->col0); 146 modelData[iy][ix] = NAN; 147 } else { 148 modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN); 146 149 } 147 modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);150 psErrorClear(); // drop errors caused by this condition 148 151 stats->options = currentOptions; 149 152 } … … 158 161 // backMdl->data.F32[iy][ix] = stats->clippedMean; 159 162 } 163 } 164 165 // patch over bad regions (use average of 8 possible neighbor pixels) 166 float Count = 0; 167 float Value = 0; 168 for (int iy = 0; iy < ny; iy++) { 169 for (int ix = 0; ix < nx; ix++) { 170 if (!isnan(modelData[iy][ix])) { 171 Value += modelData[iy][ix]; 172 Count += 1; 173 continue; 174 } 175 float value = 0; 176 float count = 0; 177 for (int jy = iy - 1; jy <= iy + 1; jy++) { 178 if (jy < 0) continue; 179 if (jy >= ny) continue; 180 for (int jx = ix - 1; jx <= ix + 1; jx++) { 181 if (!jx && !jy) continue; 182 if (jx < 0) continue; 183 if (jx >= nx) continue; 184 value += modelData[jy][jx]; 185 count += 1.0; 186 } 187 } 188 if (count > 0) modelData[iy][ix] = value / count; 189 190 } 191 } 192 Value = Value / Count; 193 194 // patch over remaining bad regions (use global average) 195 for (int iy = 0; iy < ny; iy++) { 196 for (int ix = 0; ix < nx; ix++) { 197 if (!isnan(modelData[iy][ix])) continue; 198 modelData[iy][ix] = Value; 199 } 160 200 } 161 201 psLogMsg ("psphot", 3, "build median image: %f sec\n", psTimerMark ("psphot"));
Note:
See TracChangeset
for help on using the changeset viewer.
