Changeset 11311
- Timestamp:
- Jan 25, 2007, 6:52:28 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotImageMedian.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotImageMedian.c
r11263 r11311 1 1 # include "psphot.h" 2 # define TESTSAVE 2 3 3 4 // generate the median in NxN boxes, clipping heavily … … 80 81 81 82 // overhang : we will balance this evenly 82 int dx = (Nx % DX) / 2; 83 int dy = (Ny % DY) / 2; 83 int xExtra = (Nx % DX) / 2; 84 int yExtra = (Ny % DY) / 2; 85 int xOffset = (xExtra > 0) ? DX - xExtra : 0; 86 int yOffset = (yExtra > 0) ? DY - yExtra : 0; 87 xOffset -= image->col0; 88 yOffset -= image->row0; 84 89 85 90 // dimensions of binned image 86 int nx = (Nx % DX) ? (int)(Nx / DX) + 1 : Nx / DX; 87 int ny = (Ny % DY) ? (int)(Ny / DY) + 1 : Ny / DY; 91 int nx, ny; 92 if (Nx % DX == 0) { 93 nx = Nx / DX; 94 } else { 95 nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1; 96 } 97 if (Ny % DY == 0) { 98 ny = Ny / DY; 99 } else { 100 ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1; 101 } 88 102 89 103 // select model pixels (from output background model file, or create internal file) … … 108 122 109 123 assert(model->analysis != NULL); 110 psMetadataAdd(model->analysis, PS_LIST_TAIL, " XBIN", PS_DATA_S32 | PS_META_REPLACE,124 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XBIN", PS_DATA_S32 | PS_META_REPLACE, 111 125 "Background x-binsize", DX); 112 psMetadataAdd(model->analysis, PS_LIST_TAIL, " YBIN", PS_DATA_S32 | PS_META_REPLACE,126 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YBIN", PS_DATA_S32 | PS_META_REPLACE, 113 127 "Background x-binsize", DY); 114 psMetadataAdd(model->analysis, PS_LIST_TAIL, "x0", PS_DATA_S32 | PS_META_REPLACE, 115 "Background x-overhang", dx); 116 psMetadataAdd(model->analysis, PS_LIST_TAIL, "y0", PS_DATA_S32 | PS_META_REPLACE, 117 "Background y-overhang", dy); 128 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XOFF", PS_DATA_S32 | PS_META_REPLACE, 129 "Background x-overhang", xOffset); 130 psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YOFF", PS_DATA_S32 | PS_META_REPLACE, 131 "Background y-overhang", yOffset); 132 118 133 119 134 // measure clipped median for subimages … … 121 136 for (int ix = 0; ix < nx; ix++) { 122 137 // sx, sy are in parent coords 123 int sx = ix*DX - dx + image->col0;124 int sy = iy*DY - dy + image->row0;138 int sx = ix*DX - xOffset; 139 int sy = iy*DY - yOffset; 125 140 region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY); 126 141 region = psRegionForImage (image, region); … … 133 148 psImage *submask = psImageSubset (mask, region); 134 149 135 // XXX the value of the upper and lower cuts probably should be studied... 150 // Use the selected background statistic for the first pass 151 // If it fails, fall back on the "ROBUST_MEDIAN" version 152 // If both fail, set the pixel to NAN and (below) interpolate 153 // XXX psImageBackground will probably be renamed psImageStats 136 154 if (psImageBackground(stats, subset, submask, 0xff, rng)) { 137 155 if (stats->options & PS_STAT_ROBUST_QUARTILE) { … … 151 169 modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN); 152 170 } 153 psErrorClear(); // drop errors caused by this condition 171 // drop errors caused by psImageBackground failures 172 // XXX we probably should trap and exit on serious failures 173 psErrorClear(); 154 174 stats->options = currentOptions; 155 175 } 156 176 modelData[iy][ix] += SKY_BIAS; 157 158 177 psFree (subset); 159 178 psFree (submask); 160 161 // XXX psImageStats is still very inefficient and poorly coded...162 // psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);163 // stats = psImageStats (stats, subset, maskset, 0xff);164 // backMdl->data.F32[iy][ix] = stats->clippedMean;165 179 } 166 180 } … … 243 257 244 258 // linear interpolation to full-scale 245 psImageUnbin (background->image, model->image, DX, DY, dx, dy); 259 if (!psImageUnbin (background->image, model->image, DX, DY, xOffset, yOffset)) { 260 psError (PSPHOT_ERR_PROG, true, "failed to build background iamge"); 261 return false; 262 } 263 246 264 psLogMsg ("psphot", PS_LOG_MINUTIA, "build resampled image: %f sec\n", psTimerMark ("psphot")); 247 265
Note:
See TracChangeset
for help on using the changeset viewer.
