Changeset 20755 for trunk/ppStack/src/ppStackMatch.c
- Timestamp:
- Nov 14, 2008, 12:31:34 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/ppStack/src/ppStackMatch.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackMatch.c
r20754 r20755 80 80 continue; 81 81 } 82 coords->data.F 32[0] = source->peak->xf;83 coords->data.F 32[1] = source->peak->yf;82 coords->data.F64[0] = source->peak->xf; 83 coords->data.F64[1] = source->peak->yf; 84 84 85 85 long numWithin = psTreeWithin(tree, coords, exclusion); // Number within exclusion zone 86 psTrace("ppStack", 5, "Source at %.0 f,%.0f has %ld sources in exclusion zone",87 coords->data.F 32[0], coords->data.F32[1], numWithin);86 psTrace("ppStack", 5, "Source at %.0lf,%.0lf has %ld sources in exclusion zone", 87 coords->data.F64[0], coords->data.F64[1], numWithin); 88 88 if (numWithin == 1) { 89 89 // Only itself inside the exclusion zone … … 101 101 } 102 102 103 #define BG_SIZE 64 // Large box half-size in which to measure background 104 105 // Generate a background model of the readout we're matching 106 psImage *stackBackgroundModel(pmReadout *ro, psMaskType maskVal, const psArray *sources, int size) 107 { 108 psImage *image = ro->image, *mask = ro->mask; // Image and mask of readout 109 int numCols = image->numCols, numRows = image->numRows; // Size of image 110 111 psImage *bgImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Background image 112 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for measuring background 113 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator 114 115 for (int i = 0; i < sources->n; i++) { 116 pmSource *source = sources->data[i]; // Source of interest 117 if (!source) { 118 continue; 119 } 120 121 int x = source->peak->xf + 0.5, y = source->peak->yf + 0.5; // Coordinates of source 122 123 int xMin = PS_MAX(x - BG_SIZE, 0), xMax = PS_MIN(x + BG_SIZE, numCols); 124 int yMin = PS_MAX(y - BG_SIZE, 0), yMax = PS_MIN(y + BG_SIZE, numCols); 125 126 psRegion region = psRegionSet(xMin, xMax, yMin, yMax); // Region of interest 127 psImage *subImage = psImageSubset(image, region); // Subimage 128 psImage *subMask = psImageSubset(mask, region); // Subimage mask 129 if (!psImageBackground(stats, NULL, subImage, subMask, maskVal, rng)) { 130 // Can't do anything about it 131 psErrorClear(); 132 continue; 133 } 134 psFree(subImage); 135 psFree(subMask); 136 137 float value = stats->robustMedian; // Value to set background to 138 139 int uMin = PS_MAX(x - size, 0), uMax = PS_MIN(x + size, numCols); 140 int vMin = PS_MAX(y - size, 0), vMax = PS_MIN(y + size, numCols); 141 142 for (int v = vMin; v < vMax; v++) { 143 for (int u = uMin; u < uMax; u++) { 144 bgImage->data.F32[v][u] = value; 145 } 146 } 147 } 148 149 psFree(stats); 150 psFree(rng); 151 152 return bgImage; 153 } 103 154 104 155 bool ppStackMatch(pmReadout *readout, psArray **regions, psArray **kernels, float *chi2, float *weighting, … … 242 293 psErrorClear(); 243 294 } else { 244 minFlux = 0.1 *bg->robustStdev;295 minFlux = bg->robustStdev; 245 296 } 246 297 psFree(bg); 247 298 } 248 299 300 #if 0 249 301 float maxMag = -INFINITY; // Maximum magnitude of sources 250 302 for (int i = 0; i < sources->n; i++) { … … 256 308 } 257 309 minFlux = PS_MIN(FAINT_SOURCE_FRAC * powf(10.0, -0.4 * maxMag), minFlux); 310 #endif 258 311 259 312 pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF 260 313 261 if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources, 262 NULL, NULL, psf, minFlux, 0, false)) { 314 // For the sake of stamps, remove nearby sources 315 psArray *stampSources = stackSourcesFilter(sources, footprint); // Filtered list of sources 316 317 if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, 318 stampSources, NULL, NULL, psf, minFlux, 0, false)) { 263 319 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF."); 264 320 psFree(fake); … … 267 323 return false; 268 324 } 325 326 // Add the background into the target image 327 psImage *bgImage = stackBackgroundModel(readout, maskVal, stampSources, footprint); // Image of background 328 psBinaryOp(fake->image, fake->image, "+", bgImage); 329 psFree(bgImage); 330 269 331 270 332 #ifdef TESTING … … 301 363 } 302 364 } 303 304 // For the sake of stamps, remove nearby sources305 psArray *stampSources = stackSourcesFilter(sources, footprint); // Filtered list of sources306 365 307 366 if (threads > 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
