Changeset 26747 for branches/eam_branches/psModules.stack.20100120/src/imcombine/pmSubtractionStamps.c
- Timestamp:
- Jan 31, 2010, 5:00:42 PM (16 years ago)
- Location:
- branches/eam_branches/psModules.stack.20100120
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/imcombine/pmSubtractionStamps.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/psModules.stack.20100120
- Property svn:mergeinfo changed
/branches/eam_branches/20091201/psModules (added) merged: 26686-26687,26693,26702-26703,26731-26735,26737,26739,26741-26743
- Property svn:mergeinfo changed
-
branches/eam_branches/psModules.stack.20100120/src/imcombine/pmSubtractionStamps.c
r26562 r26747 176 176 177 177 pmSubtractionStampList *pmSubtractionStampListAlloc(int numCols, int numRows, const psRegion *region, 178 int footprint, float spacing, float sysErr, float skyErr) 178 int footprint, float spacing, float normFrac, 179 float sysErr, float skyErr) 179 180 { 180 181 pmSubtractionStampList *list = psAlloc(sizeof(pmSubtractionStampList)); // Stamp list to return … … 217 218 list->flux = NULL; 218 219 list->window = NULL; 220 list->normFrac = normFrac; 221 list->normWindow = 0; 219 222 list->footprint = footprint; 220 223 list->sysErr = sysErr; … … 239 242 out->window = psMemIncrRefCounter(in->window); 240 243 out->footprint = in->footprint; 244 out->normWindow = in->normWindow; 241 245 242 246 for (int i = 0; i < num; i++) { … … 308 312 stamp->matrix = NULL; 309 313 stamp->vector = NULL; 314 stamp->norm = NAN; 310 315 311 316 return stamp; … … 316 321 const psImage *image2, const psImage *subMask, 317 322 const psRegion *region, float thresh1, float thresh2, 318 int size, int footprint, float spacing, float sysErr, float skyErr,319 pmSubtractionMode mode)323 int size, int footprint, float spacing, float normFrac, 324 float sysErr, float skyErr, pmSubtractionMode mode) 320 325 { 321 326 if (!image1 && !image2) { … … 373 378 374 379 if (!stamps) { 375 stamps = pmSubtractionStampListAlloc(numCols, numRows, region, footprint, spacing, sysErr, skyErr); 380 stamps = pmSubtractionStampListAlloc(numCols, numRows, region, footprint, spacing, 381 normFrac, sysErr, skyErr); 376 382 } 377 383 … … 407 413 // Take stamps off the top of the (sorted) list 408 414 for (int j = xList->n - 1; j >= 0 && !goodStamp; j--) { 409 int xCentre = xList->data.F32[j] + 0.5, yCentre = yList->data.F32[j] + 0.5;// Stamp centre410 411 415 // Chop off the top of the list 412 416 xList->n = j; … … 414 418 fluxList->n = j; 415 419 420 #if 0 416 421 // Fish around a bit to see if we can find a pixel that isn't masked 422 // This is not a good idea if we're using the window feature 417 423 psTrace("psModules.imcombine", 7, "Searching for stamp %d around %d,%d\n", 418 424 i, xCentre, yCentre); 419 425 420 426 // Search bounds 427 int xCentre = xList->data.F32[j] + 0.5, yCentre = yList->data.F32[j] + 0.5;// Stamp centre 421 428 int search = footprint - size; // Search radius 422 429 int xMin = PS_MAX(border, xCentre - search); … … 427 434 goodStamp = stampSearch(&xStamp, &yStamp, &fluxStamp, image1, image2, thresh1, thresh2, 428 435 subMask, xMin, xMax, yMin, yMax, numCols, numRows, border); 429 430 // XXX reset for a test: 431 xStamp = xList->data.F32[j]; 432 yStamp = yList->data.F32[j]; 436 #else 437 // Only search the exact centre pixel 438 goodStamp = stampSearch(&xStamp, &yStamp, &fluxStamp, image1, image2, thresh1, thresh2, 439 subMask, xList->data.F32[j], xList->data.F32[j], 440 yList->data.F32[j], yList->data.F32[j], numCols, numRows, border); 441 #endif 433 442 // fprintf (stderr, "find: %d %d ==> %5.1f %5.1f\n", xCentre, yCentre, xStamp, yStamp); 434 443 } … … 486 495 const psImage *image, const psImage *subMask, 487 496 const psRegion *region, int size, int footprint, 488 float spacing, float sysErr, float skyErr, pmSubtractionMode mode) 497 float spacing, float normFrac, float sysErr, float skyErr, 498 pmSubtractionMode mode) 489 499 490 500 { … … 507 517 pmSubtractionStampList *stamps = pmSubtractionStampListAlloc(subMask->numCols, subMask->numRows, 508 518 region, footprint, spacing, 509 sysErr, skyErr); // Stamp list519 normFrac, sysErr, skyErr); // Stamp list 510 520 int numStamps = stamps->num; // Number of stamps 511 521 … … 612 622 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false); 613 623 614 int size = kernelSize +stamps->footprint; // Size of postage stamps624 int size = stamps->footprint; // Size of postage stamps 615 625 616 626 psFree (stamps->window); … … 641 651 // storage vector for flux data 642 652 psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 643 psVector *flux = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32); 644 645 double maxValue = 0.0; 653 psVector *flux1 = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32); 654 psVector *flux2 = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32); 646 655 647 656 // generate the window pixels 657 double sum = 0.0; // Sum inside the window 658 float maxValue = 0.0; // Maximum value, for normalisation 648 659 for (int y = -size; y <= size; y++) { 649 660 for (int x = -size; x <= size; x++) { 650 661 651 flux->n = 0; 662 flux1->n = 0; 663 flux2->n = 0; 652 664 for (int i = 0; i < stamps->num; i++) { 653 665 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest … … 656 668 if (!stamp->image2) continue; 657 669 658 psVectorAppend (flux, stamp->image1->kernel[y][x] / norm1->data.F32[i]);659 psVectorAppend (flux, stamp->image2->kernel[y][x] / norm2->data.F32[i]);670 psVectorAppend(flux1, stamp->image1->kernel[y][x] / norm1->data.F32[i]); 671 psVectorAppend(flux2, stamp->image2->kernel[y][x] / norm2->data.F32[i]); 660 672 } 661 673 662 674 psStatsInit (stats); 663 if (!psVectorStats (stats, flux , NULL, NULL, 0)) {675 if (!psVectorStats (stats, flux1, NULL, NULL, 0)) { 664 676 psAbort ("failed to generate stats"); 665 677 } 666 stamps->window->kernel[y][x] = stats->robustMedian; 667 if (maxValue < stats->robustMedian) { 668 maxValue = stats->robustMedian; 669 } 670 } 678 float f1 = stats->robustMedian; 679 psStatsInit (stats); 680 if (!psVectorStats (stats, flux2, NULL, NULL, 0)) { 681 psAbort ("failed to generate stats"); 682 } 683 float f2 = stats->robustMedian; 684 685 stamps->window->kernel[y][x] = f1 + f2; 686 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(size)) { 687 sum += stamps->window->kernel[y][x]; 688 } 689 maxValue = PS_MAX(maxValue, stamps->window->kernel[y][x]); 690 } 691 } 692 693 psTrace("psModules.imcombine", 3, "Window total: %f, threshold: %f\n", 694 sum, (1.0 - stamps->normFrac) * sum); 695 bool done = false; 696 for (int radius = 1; radius <= size && !done; radius++) { 697 double within = 0.0; 698 for (int y = -radius; y <= radius; y++) { 699 for (int x = -radius; x <= radius; x++) { 700 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(radius)) { 701 within += stamps->window->kernel[y][x]; 702 } 703 } 704 } 705 psTrace("psModules.imcombine", 5, "Radius %d: %f\n", radius, within); 706 if (within > (1.0 - stamps->normFrac) * sum) { 707 stamps->normWindow = radius; 708 done = true; 709 } 710 } 711 712 psTrace("psModules.imcombine", 3, "Normalisation window radius set to %d\n", stamps->normWindow); 713 if (stamps->normWindow == 0 || stamps->normWindow >= size) { 714 psError(PS_ERR_UNKNOWN, true, "Unable to determine normalisation window size."); 715 return false; 671 716 } 672 717 … … 678 723 } 679 724 680 # ifdef TESTING725 #if 0 681 726 { 682 727 psFits *fits = psFitsOpen ("window.fits", "w"); … … 684 729 psFitsClose (fits); 685 730 } 686 # endif731 #endif 687 732 688 733 psFree (stats); 689 psFree (flux); 734 psFree (flux1); 735 psFree(flux2); 690 736 psFree (norm1); 691 737 psFree (norm2); … … 694 740 695 741 bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage *image1, psImage *image2, 696 psImage *variance, int kernelSize )742 psImage *variance, int kernelSize, psRegion bounds) 697 743 { 698 744 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 711 757 } 712 758 713 int numCols = image1->numCols, numRows = image1->numRows; // Size of images714 759 int size = kernelSize + stamps->footprint; // Size of postage stamps 715 760 … … 720 765 } 721 766 722 if (isnan(stamp->xNorm)) { 723 stamp->xNorm = 2.0 * (stamp->x - (float)numCols/2.0) / (float)numCols; 724 } 725 if (isnan(stamp->yNorm)) { 726 stamp->yNorm = 2.0 * (stamp->y - (float)numRows/2.0) / (float)numRows; 727 } 767 p_pmSubtractionPolynomialNormCoords(&stamp->xNorm, &stamp->yNorm, stamp->x, stamp->y, 768 bounds.x0, bounds.x1, bounds.y0, bounds.y1); 728 769 729 770 int x = stamp->x + 0.5, y = stamp->y + 0.5; // Stamp coordinates 730 if (x < size || x > numCols - size || y < size || y > numRows- size) {731 psError(PS_ERR_UNKNOWN, false, "Stamp %d (%d,%d) is within the imageborder.\n", i, x, y);771 if (x < bounds.x0 + size || x > bounds.x1 - size || y < bounds.y0 + size || y > bounds.y1 - size) { 772 psError(PS_ERR_UNKNOWN, false, "Stamp %d (%d,%d) is within the region border.\n", i, x, y); 732 773 return false; 733 774 } … … 788 829 pmSubtractionStampList *pmSubtractionStampsSetFromSources(const psArray *sources, const psImage *image, 789 830 const psImage *subMask, const psRegion *region, 790 int size, int footprint, float spacing, float sysErr, float skyErr, 831 int size, int footprint, float spacing, 832 float normFrac, float sysErr, float skyErr, 791 833 pmSubtractionMode mode) 792 834 { … … 819 861 820 862 pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, size, 821 footprint, spacing, sysErr, skyErr, mode); // Stamps 863 footprint, spacing, normFrac, 864 sysErr, skyErr, mode); // Stamps 822 865 psFree(x); 823 866 psFree(y); … … 833 876 pmSubtractionStampList *pmSubtractionStampsSetFromFile(const char *filename, const psImage *image, 834 877 const psImage *subMask, const psRegion *region, 835 int size, int footprint, float spacing, float sysErr, float skyErr,836 pmSubtractionMode mode)878 int size, int footprint, float spacing, float normFrac, 879 float sysErr, float skyErr, pmSubtractionMode mode) 837 880 { 838 881 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); … … 851 894 852 895 pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, image, subMask, region, size, footprint, 853 spacing, sysErr, skyErr, mode);896 spacing, normFrac, sysErr, skyErr, mode); 854 897 psFree(data); 855 898
Note:
See TracChangeset
for help on using the changeset viewer.
