Changeset 26035 for trunk/psModules/src/imcombine/pmSubtractionStamps.c
- Timestamp:
- Nov 4, 2009, 4:52:05 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r25120 r26035 54 54 psFree(stamp->image1); 55 55 psFree(stamp->image2); 56 psFree(stamp-> variance);56 psFree(stamp->weight); 57 57 psFree(stamp->convolutions1); 58 58 psFree(stamp->convolutions2); … … 180 180 181 181 pmSubtractionStampList *pmSubtractionStampListAlloc(int numCols, int numRows, const psRegion *region, 182 int footprint, float spacing )182 int footprint, float spacing, float sysErr) 183 183 { 184 184 pmSubtractionStampList *list = psAlloc(sizeof(pmSubtractionStampList)); // Stamp list to return … … 221 221 list->flux = NULL; 222 222 list->footprint = footprint; 223 list->sysErr = sysErr; 223 224 224 225 return list; … … 256 257 outStamp->image1 = inStamp->image1 ? psKernelCopy(inStamp->image1) : NULL; 257 258 outStamp->image2 = inStamp->image2 ? psKernelCopy(inStamp->image2) : NULL; 258 outStamp-> variance = inStamp->variance ? psKernelCopy(inStamp->variance) : NULL;259 outStamp->weight = inStamp->weight ? psKernelCopy(inStamp->weight) : NULL; 259 260 260 261 if (inStamp->convolutions1) { … … 305 306 stamp->image1 = NULL; 306 307 stamp->image2 = NULL; 307 stamp-> variance= NULL;308 stamp->weight = NULL; 308 309 stamp->convolutions1 = NULL; 309 310 stamp->convolutions2 = NULL; … … 322 323 const psImage *image2, const psImage *subMask, 323 324 const psRegion *region, float thresh1, float thresh2, 324 int size, int footprint, float spacing, 325 int size, int footprint, float spacing, float sysErr, 325 326 pmSubtractionMode mode) 326 327 { … … 379 380 380 381 if (!stamps) { 381 stamps = pmSubtractionStampListAlloc(numCols, numRows, region, footprint, spacing );382 stamps = pmSubtractionStampListAlloc(numCols, numRows, region, footprint, spacing, sysErr); 382 383 } 383 384 … … 452 453 psFree(stamp->image1); 453 454 psFree(stamp->image2); 454 psFree(stamp-> variance);455 psFree(stamp->weight); 455 456 psFree(stamp->convolutions1); 456 457 psFree(stamp->convolutions2); 457 stamp->image1 = stamp->image2 = stamp-> variance= NULL;458 stamp->image1 = stamp->image2 = stamp->weight = NULL; 458 459 stamp->convolutions1 = stamp->convolutions2 = NULL; 459 460 … … 487 488 const psImage *image, const psImage *subMask, 488 489 const psRegion *region, int size, int footprint, 489 float spacing, pmSubtractionMode mode)490 float spacing, float sysErr, pmSubtractionMode mode) 490 491 491 492 { … … 507 508 int numStars = x->n; // Number of stars 508 509 pmSubtractionStampList *stamps = pmSubtractionStampListAlloc(subMask->numCols, subMask->numRows, 509 region, footprint, spacing); // Stamp list 510 region, footprint, sysErr, 511 spacing); // Stamp list 510 512 int numStamps = stamps->num; // Number of stamps 511 513 … … 616 618 PS_ASSERT_IMAGE_TYPE(image2, PS_TYPE_F32, false); 617 619 } 618 PS_ASSERT_IMAGE_NON_NULL(variance, false); 619 PS_ASSERT_IMAGES_SIZE_EQUAL(variance, image1, false); 620 PS_ASSERT_IMAGE_TYPE(variance, PS_TYPE_F32, false); 621 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false); 620 if (variance) { 621 PS_ASSERT_IMAGE_NON_NULL(variance, false); 622 PS_ASSERT_IMAGES_SIZE_EQUAL(variance, image1, false); 623 PS_ASSERT_IMAGE_TYPE(variance, PS_TYPE_F32, false); 624 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false); 625 } 622 626 623 627 int numCols = image1->numCols, numRows = image1->numRows; // Size of images … … 646 650 assert(stamp->image1 == NULL); 647 651 assert(stamp->image2 == NULL); 648 assert(stamp-> variance== NULL);652 assert(stamp->weight == NULL); 649 653 650 654 psRegion region = psRegionSet(x - size, x + size + 1, y - size, y + size + 1); // Region of interest … … 660 664 } 661 665 662 psImage *wtSub = psImageSubset(variance, region); // Subimage with stamp 663 stamp->variance = psKernelAllocFromImage(wtSub, size, size); 664 psFree(wtSub); // Drop reference 666 psKernel *weight = stamp->weight = psKernelAlloc(-size, size, -size, size); // Weight = 1/variance 667 if (variance) { 668 psImage *varSub = psImageSubset(variance, region); // Subimage with stamp 669 psKernel *var = psKernelAllocFromImage(varSub, size, size); // Variance postage stamp 670 if (isfinite(stamps->sysErr) && stamps->sysErr > 0) { 671 float sysErr = 0.5 * stamps->sysErr; // Systematic error 672 psKernel *image1 = stamp->image1, *image2 = stamp->image2; // Input images 673 for (int y = -size; y <= size; y++) { 674 for (int x = -size; x <= size; x++) { 675 weight->kernel[y][x] = 1.0 / (var->kernel[y][x] + 676 sysErr * (image1->kernel[y][x] + image2->kernel[y][x])); 677 } 678 } 679 } else { 680 for (int y = -size; y <= size; y++) { 681 for (int x = -size; x <= size; x++) { 682 weight->kernel[y][x] = 1.0 / var->kernel[y][x]; 683 } 684 } 685 } 686 psFree(var); 687 psFree(varSub); 688 } else { 689 psImageInit(weight->image, 1.0); 690 } 665 691 666 692 stamp->status = PM_SUBTRACTION_STAMP_CALCULATE; … … 672 698 pmSubtractionStampList *pmSubtractionStampsSetFromSources(const psArray *sources, const psImage *image, 673 699 const psImage *subMask, const psRegion *region, 674 int size, int footprint, float spacing, 700 int size, int footprint, float spacing, float sysErr, 675 701 pmSubtractionMode mode) 676 702 { … … 702 728 703 729 pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, size, 704 footprint, spacing, mode); // Stamps to return730 footprint, spacing, sysErr, mode); // Stamps 705 731 psFree(x); 706 732 psFree(y); … … 716 742 pmSubtractionStampList *pmSubtractionStampsSetFromFile(const char *filename, const psImage *image, 717 743 const psImage *subMask, const psRegion *region, 718 int size, int footprint, float spacing, 744 int size, int footprint, float spacing, float sysErr, 719 745 pmSubtractionMode mode) 720 746 { … … 734 760 735 761 pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, size, footprint, 736 spacing, mode);762 spacing, sysErr, mode); 737 763 psFree(data); 738 764
Note:
See TracChangeset
for help on using the changeset viewer.
