Changeset 6379 for trunk/psphot/src/psphotBasicDeblend.c
- Timestamp:
- Feb 7, 2006, 8:52:03 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotBasicDeblend.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotBasicDeblend.c
r6319 r6379 1 1 # include "psphot.h" 2 2 3 // 2006.02.02 : no leaks? (creates source->blend entries) 4 // XXX if I free sources, I still have 54 leaks? 3 // 2006.02.07 : no leaks 5 4 bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky) { 6 5 … … 35 34 // this results in an index of increasing SN 36 35 37 // temporary array for overlapping objects we find38 psArray *overlap = psArrayAlloc (100);39 40 36 // examine sources in decreasing SN order 41 37 for (int i = sources->n - 1; i >= 0; i--) { … … 45 41 if (source->mode & PM_SOURCE_BLEND) continue; 46 42 43 // temporary array for overlapping objects we find 44 // XXX psArrayAlloc should set ->n to 0 *and* all objects to NULL 45 // XXX I need a psArrayEmpty function to free the elements without the array 46 // XXX then, I could allocate 'overlap' once outside the loop and only 47 // XXX clear at the end of each loop 48 psArray *overlap = psArrayAlloc (100); 47 49 overlap->n = 0; 48 50 … … 73 75 } 74 76 77 if (overlap->n == 0) { 78 psFree (overlap); 79 continue; 80 } 81 82 // this source has overlapping neighbors, check for actual blends 75 83 // generate source contour (1/4 peak counts) 76 if (overlap->n > 0) { 77 // set the threshold based on user inputs 78 threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky; 79 threshold = PS_MAX (threshold, minThreshold); 84 // set the threshold based on user inputs 85 threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky; 86 threshold = PS_MAX (threshold, minThreshold); 80 87 81 // generate a basic contour (set of x,y coordinates at-or-below flux level) 82 psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold); 83 if (contour == NULL) continue; 88 // generate a basic contour (set of x,y coordinates at-or-below flux level) 89 psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold); 90 if (contour == NULL) { 91 psFree (overlap); 92 continue; 93 } 84 94 85 // the source contour consists of two vectors, xv and yv. the contour is86 // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]). both87 // coordinate pairs have the same yv[] value, with xv[i] corresponding to88 // the left boundary and xv[i+1] corresponding to the right boundary95 // the source contour consists of two vectors, xv and yv. the contour is 96 // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]). both 97 // coordinate pairs have the same yv[] value, with xv[i] corresponding to 98 // the left boundary and xv[i+1] corresponding to the right boundary 89 99 90 psVector *xv = contour->data[0];91 psVector *yv = contour->data[1];92 for (int k = 0; k < overlap->n; k++) {93 testSource = overlap->data[k];94 if (testSource->peak->counts > source->peak->counts) continue;95 for (int j = 0; j < xv->n; j+=2) {96 if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;97 if (xv->data.F32[j+0] > testSource->peak->x) break;98 if (xv->data.F32[j+1] < testSource->peak->x) break;100 psVector *xv = contour->data[0]; 101 psVector *yv = contour->data[1]; 102 for (int k = 0; k < overlap->n; k++) { 103 testSource = overlap->data[k]; 104 if (testSource->peak->counts > source->peak->counts) continue; 105 for (int j = 0; j < xv->n; j+=2) { 106 if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue; 107 if (xv->data.F32[j+0] > testSource->peak->x) break; 108 if (xv->data.F32[j+1] < testSource->peak->x) break; 99 109 100 testSource->mode |= PM_SOURCE_BLEND;110 testSource->mode |= PM_SOURCE_BLEND; 101 111 102 // add this to the list of source->blends 103 if (source->blends == NULL) { 104 source->blends = psArrayAlloc (16); 105 source->blends->n = 0; 106 } 107 psArrayAdd (source->blends, 16, testSource); 112 // add this to the list of source->blends 113 if (source->blends == NULL) { 114 source->blends = psArrayAlloc (16); 115 source->blends->n = 0; 116 } 108 117 109 Nblend ++; 110 j = xv->n; 111 } 112 } 113 psFree (contour); 114 } 118 psArrayAdd (source->blends, 16, testSource); 119 120 Nblend ++; 121 j = xv->n; 122 } 123 } 124 psFree (overlap); 125 psFree (contour); 115 126 } 116 127 psLogMsg ("psphot.deblend", 3, "identified %d blended objects (%f sec)\n", Nblend, psTimerMark ("psphot")); 117 128 118 char *breakPt = psMetadataLookup Ptr (&status, config, "BREAK_POINT");129 char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT"); 119 130 if (!strcasecmp (breakPt, "DEBLEND")) exit (0); 120 131 121 132 psFree (SN); 122 133 psFree (index); 123 psFree (overlap);124 125 134 return true; 126 135 }
Note:
See TracChangeset
for help on using the changeset viewer.
