Changeset 14514
- Timestamp:
- Aug 15, 2007, 2:08:27 PM (19 years ago)
- Location:
- trunk/psModules/src/imcombine
- Files:
-
- 2 edited
-
pmSubtractionStamps.c (modified) (10 diffs)
-
pmSubtractionStamps.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r14513 r14514 9 9 #include "pmSubtractionStamps.h" 10 10 11 12 #define PM_SUBTRACTION_MASK_BAD_STAMP (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_FOOTPRINT | \13 PM_SUBTRACTION_MASK_REJ) // Mask indicates a stamp would be bad14 15 16 11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 12 // Private (file-static) functions … … 24 19 psFree(stamp->matrix); 25 20 psFree(stamp->vector); 26 } 27 21 psFree(stamp->reference); 22 psFree(stamp->input); 23 psFree(stamp->weight); 24 } 25 26 // Is this region OK? 27 static bool checkStampRegion(int x, int y, // Coordinates of stamp 28 const psRegion *region // Region of interest 29 ) 30 { 31 if (!region) { 32 return true; 33 } 34 return (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) ? 35 false : true; 36 } 37 38 // Is this position unmasked? 39 static bool checkStampMask(int x, int y, // Coordinates of stamp 40 const psImage *mask 41 ) 42 { 43 if (!mask) { 44 return true; 45 } 46 return (mask->data.PS_TYPE_MASK_DATA[y][x] & (PM_SUBTRACTION_MASK_BORDER | 47 PM_SUBTRACTION_MASK_FOOTPRINT | PM_SUBTRACTION_MASK_REJ)) ? 48 false : true; 49 } 28 50 29 51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 38 60 stamp->x = NAN; 39 61 stamp->y = NAN; 62 stamp->flux = NAN; 40 63 stamp->xNorm = NAN; 41 64 stamp->yNorm = NAN; … … 135 158 for (int y = yStart; y <= yStop ; y++) { 136 159 for (int x = xStart; x <= xStop ; x++) { 137 if ((!subMask || !(subMask->data.PS_TYPE_MASK_DATA[y][x] & 138 PM_SUBTRACTION_MASK_BAD_STAMP)) && 139 image->data.F32[y][x] > fluxBest) { 160 if (checkStampMask(x, y, subMask) && image->data.F32[y][x] > fluxBest) { 140 161 fluxBest = image->data.F32[y][x]; 141 162 xBest = x; … … 147 168 stamp->x = xBest; 148 169 stamp->y = yBest; 170 stamp->flux = fluxBest; 149 171 150 172 // Reset the postage stamps since we're making a new stamp … … 173 195 174 196 175 psArray *pmSubtractionSetStamps(const psVector *x, const psVector *y, 197 psArray *pmSubtractionSetStamps(const psVector *x, const psVector *y, const psVector *flux, 176 198 const psImage *subMask, const psRegion *region) 177 199 { … … 181 203 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false); 182 204 PS_ASSERT_VECTORS_SIZE_EQUAL(y, x, false); 205 if (flux) { 206 PS_ASSERT_VECTOR_NON_NULL(flux, false); 207 PS_ASSERT_VECTOR_TYPE(flux, PS_TYPE_F32, false); 208 PS_ASSERT_VECTORS_SIZE_EQUAL(flux, x, false); 209 } 183 210 if (subMask) { 184 211 PS_ASSERT_IMAGE_NON_NULL(subMask, false); … … 191 218 for (int i = 0; i < num; i++) { 192 219 int xStamp = x->data.F32[i] + 0.5, yStamp = y->data.F32[i] + 0.5; // Pixel coords of stamp 193 if (region && (xStamp < region->x0 || xStamp > region->x1 || 194 yStamp < region->y0 || yStamp > region->y1)) { 195 // Not interested at this time 196 continue; 197 } 198 199 if (subMask && subMask->data.PS_TYPE_MASK_DATA[yStamp][xStamp] & PM_SUBTRACTION_MASK_BAD_STAMP) { 200 // It's bad 220 if (!checkStampRegion(xStamp, yStamp, region)) { 221 continue; 222 } 223 if (!checkStampMask(xStamp, yStamp, subMask)) { 201 224 continue; 202 225 } … … 205 228 stamp->x = x->data.F32[i]; 206 229 stamp->y = y->data.F32[i]; 230 if (flux) { 231 stamp->flux = flux->data.F32[i]; 232 } 207 233 stamps->data[stamps->n++] = stamp; 208 234 } … … 278 304 279 305 280 psArray *pmSubtractionGenerateStamps(const psVector *x, const psVector *y, const psVector *flux, 281 float sigma, int footprint, const pmSubtractionKernels *kernels) 282 { 283 PS_ASSERT_VECTOR_NON_NULL(x, false); 284 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false); 285 PS_ASSERT_VECTOR_NON_NULL(y, false); 286 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false); 287 PS_ASSERT_VECTORS_SIZE_EQUAL(y, x, false); 288 PS_ASSERT_VECTOR_NON_NULL(flux, false); 289 PS_ASSERT_VECTOR_TYPE(flux, PS_TYPE_F32, false); 290 PS_ASSERT_VECTORS_SIZE_EQUAL(flux, y, false); 306 bool pmSubtractionGenerateStamps(psArray *stamps, float sigma, int footprint, 307 const pmSubtractionKernels *kernels) 308 { 309 PS_ASSERT_ARRAY_NON_NULL(stamps, false); 291 310 PS_ASSERT_FLOAT_LARGER_THAN(sigma, 0.0, false); 311 PS_ASSERT_INT_NONNEGATIVE(footprint, false); 292 312 293 313 int size = kernels->size + footprint; // Size of postage stamps 294 int num = x->n; // Number of stamps 295 psArray *stamps = psArrayAlloc(num); // Stamps, to return 314 int num = stamps->n; // Number of stamps 296 315 297 316 for (int i = 0; i < num; i++) { 298 pmSubtractionStamp *stamp = pmSubtractionStampAlloc(PM_SUBTRACTION_STAMP_CALCULATE); // Stamp 299 stamps->data[i] = stamp; 300 301 stamp->x = x->data.F32[i]; 302 stamp->y = y->data.F32[i]; 303 304 float xStamp = x->data.F32[i] - (int)(stamp->x + 0.5); // x coordinate of star in stamp frame 305 float yStamp = y->data.F32[i] - (int)(stamp->y + 0.5); // y coordinate of star in stamp frame 306 float fluxStamp = flux->data.F32[i]; // Flux of star 307 317 pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest 318 if (!(stamp->status & PM_SUBTRACTION_STAMP_CALCULATE)) { 319 continue; 320 } 321 322 float x = stamp->x, y = stamp->y; // Coordinates of stamp 323 float flux = stamp->flux; // Flux of star 324 if (!isfinite(flux)) { 325 psWarning("Unable to generate PSF for stamp %d --- bad flux.", i); 326 continue; 327 } 328 329 float xStamp = x - (int)(x + 0.5); // x coordinate of star in stamp frame 330 float yStamp = y - (int)(y + 0.5); // y coordinate of star in stamp frame 331 332 psFree(stamp->input); 308 333 stamp->input = psKernelAlloc(-size, size, -size, size); 309 334 psKernel *input = stamp->input; // Target stamp 310 335 311 336 // Put in a Gaussian, just for fun! 312 for (int y = -size; y <= size; y++) {313 for (int x = -size; x <= size; x++) {314 input->kernel[ y][x] = fluxStamp/ sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 *315 expf(0.5 * (PS_SQR( x + xStamp) + PS_SQR(y+ yStamp)) / PS_SQR(sigma));337 for (int v = -size; v <= size; v++) { 338 for (int u = -size; u <= size; u++) { 339 input->kernel[v][u] = flux / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 * 340 expf(0.5 * (PS_SQR(u + xStamp) + PS_SQR(v + yStamp)) / PS_SQR(sigma)); 316 341 } 317 342 } -
trunk/psModules/src/imcombine/pmSubtractionStamps.h
r14513 r14514 18 18 typedef struct { 19 19 float x, y; ///< Position 20 float flux; ///< Flux 20 21 float xNorm, yNorm; ///< Normalised position 21 22 psKernel *reference; ///< Reference image postage stamp … … 39 40 psArray *pmSubtractionSetStamps(const psVector *x, ///< x coordinates for each stamp 40 41 const psVector *y, ///< y coordinates for each stamp 42 const psVector *flux, ///< Flux for each stamp, or NULL 41 43 const psImage *mask, ///< Mask, or NULL 42 44 const psRegion *region ///< Region in which to search for stamps, or NULL … … 53 55 54 56 /// Generate target for stamps based on list 55 psArray *pmSubtractionGenerateStamps(const psVector *x, ///< x coordinates for each stamp 56 const psVector *y, ///< y coordinates for each stamp 57 const psVector *flux, ///< Flux for each stamp 58 float sigma, ///< Gaussian width for each stamp 59 int footprint, ///< Stamp footprint size 60 const pmSubtractionKernels *kernels ///< Kernel basis functions 57 bool pmSubtractionGenerateStamps(psArray *stamps, ///< Stamps 58 float sigma, ///< Gaussian width for each stamp 59 int footprint, ///< Stamp footprint size 60 const pmSubtractionKernels *kernels ///< Kernel basis functions 61 61 ); 62 62
Note:
See TracChangeset
for help on using the changeset viewer.
