IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17462


Ignore:
Timestamp:
Apr 21, 2008, 8:21:54 AM (18 years ago)
Author:
eugene
Message:

changed usage of psArrayRemoveIndex to an algorithm which saves the new peaks in a separate array (cleaner on array api as well)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080413/psphot/src/psphotCullPeaks.c

    r17443 r17462  
    5252  * starting point, discard the peak.
    5353  */
    54 psErrorCode pmFootprintCullPeaks(const psImage *img, // the image wherein lives the footprint
     54psErrorCode pmFootprintCullPeaks_OLD(const psImage *img, // the image wherein lives the footprint
    5555                                 const psImage *weight, // corresponding variance image
    5656                                 pmFootprint *fp, // Footprint containing mortal peaks
     
    125125        pmFootprint *peakFootprint = pmFootprintsFindAtPoint(subImg, threshold, brightPeaks, peak->y, peak->x);
    126126        brightPeaks->n = 0;             // don't double free
    127         psImage *idImg = pmSetFootprintID(peakFootprint, peak_id);
     127        psImage *idImg = pmSetFootprintID(NULL, peakFootprint, peak_id);
    128128        psFree(peakFootprint);
    129129
     
    158158}
    159159
     160 /*
     161  * Examine the peaks in a pmFootprint, and throw away the ones that are not sufficiently
     162  * isolated.  More precisely, for each peak find the highest coll that you'd have to traverse
     163  * to reach a still higher peak --- and if that coll's more than nsigma DN below your
     164  * starting point, discard the peak.
     165  */
     166
     167# define IN_PEAK 1
     168psErrorCode pmFootprintCullPeaks(const psImage *img, // the image wherein lives the footprint
     169                                 const psImage *weight, // corresponding variance image
     170                                 pmFootprint *fp, // Footprint containing mortal peaks
     171                                 const float nsigma_delta, // how many sigma above local background a peak
     172                                 // needs to be to survive
     173                                 const float min_threshold) { // minimum permitted coll height
     174    assert (img != NULL); assert (img->type.type == PS_TYPE_F32);
     175    assert (weight != NULL); assert (weight->type.type == PS_TYPE_F32);
     176    assert (img->row0 == weight->row0 && img->col0 == weight->col0);
     177    assert (fp != NULL);
     178
     179    if (fp->peaks == NULL || fp->peaks->n == 0) { // nothing to do
     180        return PS_ERR_NONE;
     181    }
     182
     183    psRegion subRegion;                 // desired subregion; 1 larger than bounding box (grr)
     184    subRegion.x0 = fp->bbox.x0; subRegion.x1 = fp->bbox.x1 + 1;
     185    subRegion.y0 = fp->bbox.y0; subRegion.y1 = fp->bbox.y1 + 1;
     186
     187    psImage *subImg = psImageSubset((psImage *)img, subRegion);
     188    psImage *subWt = psImageSubset((psImage *)weight, subRegion);
     189    assert (subImg != NULL && subWt != NULL);
     190
     191    psImage *idImg = psImageAlloc(subImg->numCols, subImg->numRows, PS_TYPE_S32);
     192
     193    // We need a psArray of peaks brighter than the current peak. 
     194    // We reject peaks which either:
     195    // 1) are below the local threshold
     196    // 2) have a brighter peak within their threshold
     197
     198    // allocate the full-sized array.  if the final array is much smaller, we can realloc
     199    // at that point.
     200    psArray *brightPeaks = psArrayAllocEmpty(fp->peaks->n);
     201    psArrayAdd (brightPeaks, 128, fp->peaks->data[0]);
     202
     203    // The brightest peak is always safe; go through other peaks trying to cull them
     204    for (int i = 1; i < fp->peaks->n; i++) { // n.b. fp->peaks->n can change within the loop
     205        const pmPeak *peak = fp->peaks->data[i];
     206        int x = peak->x - subImg->col0;
     207        int y = peak->y - subImg->row0;
     208        //
     209        // Find the level nsigma below the peak that must separate the peak
     210        // from any of its friends
     211        //
     212        assert (x >= 0 && x < subImg->numCols && y >= 0 && y < subImg->numRows);
     213        const float stdev = sqrt(subWt->data.F32[y][x]);
     214        float threshold = subImg->data.F32[y][x] - nsigma_delta*stdev;
     215        if (isnan(threshold) || threshold < min_threshold) {
     216            // min_threshold is assumed to be below the detection threshold,
     217            // so all the peaks are pmFootprint, and this isn't the brightest
     218            continue;
     219        }
     220
     221        // XXX EAM : if stdev >= 0, i'm not sure how this can ever be true?
     222        if (threshold > subImg->data.F32[y][x]) {
     223            threshold = subImg->data.F32[y][x] - 10*FLT_EPSILON;
     224        }
     225
     226        // XXX this is a bit expensive: psImageAlloc for every peak contained in this footprint
     227        // perhaps this should alloc a single ID image above and pass it in to be set.
     228
     229        // XXX optionally use the faster pmFootprintsFind if the subimage size is large (eg, M31)
     230
     231        // at this point brightPeaks only has the peaks brighter than the current
     232        pmFootprint *peakFootprint = pmFootprintsFindAtPoint(subImg, threshold, brightPeaks, peak->y, peak->x);
     233
     234        // XXX need to supply the image here
     235        // we set the IDs to either 1 (in peak) or 0 (not in peak)
     236        pmSetFootprintID (idImg, peakFootprint, IN_PEAK);
     237        psFree(peakFootprint);
     238
     239        // Check if any of the previous (brighter) peaks are within the footprint of this peak
     240        // If so, the current peak is bogus; drop it.
     241        bool keep = true;
     242        for (int j = 0; keep && (j < brightPeaks->n); j++) {
     243            const pmPeak *peak2 = fp->peaks->data[j];
     244            int x2 = peak2->x - subImg->col0;
     245            int y2 = peak2->y - subImg->row0;
     246            if (idImg->data.S32[y2][x2] == IN_PEAK)
     247                // There's a brighter peak within the footprint above threshold; so cull our initial peak
     248                keep = false;
     249        }
     250        if (!keep) continue;
     251
     252        psArrayAdd (brightPeaks, 128, fp->peaks->data[i]);
     253    }
     254
     255    psFree (fp->peaks);
     256    fp->peaks = brightPeaks;
     257
     258    psFree(idImg);
     259    psFree(subImg);
     260    psFree(subWt);
     261
     262    return PS_ERR_NONE;
     263}
     264
Note: See TracChangeset for help on using the changeset viewer.