IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20755


Ignore:
Timestamp:
Nov 14, 2008, 12:31:34 AM (17 years ago)
Author:
Paul Price
Message:

Filter out sources for stamps before making the fake image. Correct
the fake image with the background around the stamp stars. This seems
to be important, to prevent the convolved image becoming noisy and
around zero.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStackMatch.c

    r20754 r20755  
    8080            continue;
    8181        }
    82         coords->data.F32[0] = source->peak->xf;
    83         coords->data.F32[1] = source->peak->yf;
     82        coords->data.F64[0] = source->peak->xf;
     83        coords->data.F64[1] = source->peak->yf;
    8484
    8585        long numWithin = psTreeWithin(tree, coords, exclusion); // Number within exclusion zone
    86         psTrace("ppStack", 5, "Source at %.0f,%.0f has %ld sources in exclusion zone",
    87                 coords->data.F32[0], coords->data.F32[1], numWithin);
     86        psTrace("ppStack", 5, "Source at %.0lf,%.0lf has %ld sources in exclusion zone",
     87                coords->data.F64[0], coords->data.F64[1], numWithin);
    8888        if (numWithin == 1) {
    8989            // Only itself inside the exclusion zone
     
    101101}
    102102
     103#define BG_SIZE 64                      // Large box half-size in which to measure background
     104
     105// Generate a background model of the readout we're matching
     106psImage *stackBackgroundModel(pmReadout *ro, psMaskType maskVal, const psArray *sources, int size)
     107{
     108    psImage *image = ro->image, *mask = ro->mask; // Image and mask of readout
     109    int numCols = image->numCols, numRows = image->numRows; // Size of image
     110
     111    psImage *bgImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Background image
     112    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for measuring background
     113    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
     114
     115    for (int i = 0; i < sources->n; i++) {
     116        pmSource *source = sources->data[i]; // Source of interest
     117        if (!source) {
     118            continue;
     119        }
     120
     121        int x = source->peak->xf + 0.5, y = source->peak->yf + 0.5; // Coordinates of source
     122
     123        int xMin = PS_MAX(x - BG_SIZE, 0), xMax = PS_MIN(x + BG_SIZE, numCols);
     124        int yMin = PS_MAX(y - BG_SIZE, 0), yMax = PS_MIN(y + BG_SIZE, numCols);
     125
     126        psRegion region = psRegionSet(xMin, xMax, yMin, yMax); // Region of interest
     127        psImage *subImage = psImageSubset(image, region); // Subimage
     128        psImage *subMask = psImageSubset(mask, region); // Subimage mask
     129        if (!psImageBackground(stats, NULL, subImage, subMask, maskVal, rng)) {
     130            // Can't do anything about it
     131            psErrorClear();
     132            continue;
     133        }
     134        psFree(subImage);
     135        psFree(subMask);
     136
     137        float value = stats->robustMedian; // Value to set background to
     138
     139        int uMin = PS_MAX(x - size, 0), uMax = PS_MIN(x + size, numCols);
     140        int vMin = PS_MAX(y - size, 0), vMax = PS_MIN(y + size, numCols);
     141
     142        for (int v = vMin; v < vMax; v++) {
     143            for (int u = uMin; u < uMax; u++) {
     144                bgImage->data.F32[v][u] = value;
     145            }
     146        }
     147    }
     148
     149    psFree(stats);
     150    psFree(rng);
     151
     152    return bgImage;
     153}
    103154
    104155bool ppStackMatch(pmReadout *readout, psArray **regions, psArray **kernels, float *chi2, float *weighting,
     
    242293                    psErrorClear();
    243294                } else {
    244                     minFlux = 0.1 * bg->robustStdev;
     295                    minFlux = bg->robustStdev;
    245296                }
    246297                psFree(bg);
    247298            }
    248299
     300#if 0
    249301            float maxMag = -INFINITY;   // Maximum magnitude of sources
    250302            for (int i = 0; i < sources->n; i++) {
     
    256308            }
    257309            minFlux = PS_MIN(FAINT_SOURCE_FRAC * powf(10.0, -0.4 * maxMag), minFlux);
     310#endif
    258311
    259312            pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
    260313
    261             if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources,
    262                                           NULL, NULL, psf, minFlux, 0, false)) {
     314            // For the sake of stamps, remove nearby sources
     315            psArray *stampSources = stackSourcesFilter(sources, footprint); // Filtered list of sources
     316
     317            if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows,
     318                                          stampSources, NULL, NULL, psf, minFlux, 0, false)) {
    263319                psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF.");
    264320                psFree(fake);
     
    267323                return false;
    268324            }
     325
     326            // Add the background into the target image
     327            psImage *bgImage = stackBackgroundModel(readout, maskVal, stampSources, footprint); // Image of background
     328            psBinaryOp(fake->image, fake->image, "+", bgImage);
     329            psFree(bgImage);
     330
    269331
    270332#ifdef TESTING
     
    301363                }
    302364            }
    303 
    304             // For the sake of stamps, remove nearby sources
    305             psArray *stampSources = stackSourcesFilter(sources, footprint); // Filtered list of sources
    306365
    307366            if (threads > 0) {
Note: See TracChangeset for help on using the changeset viewer.