IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 31, 2008, 12:39:06 PM (18 years ago)
Author:
Paul Price
Message:

Adding assertion macros for readouts (about time too!). Adding function to renormalise the weight map to correspond to the measured image stdev.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAMaskWeight.c

    r15307 r17249  
    305305    for (int i = 0; i < readouts->n; i++) {
    306306        pmReadout *readout = readouts->data[i]; // The readout
    307         pmReadoutGenerateMaskWeight(readout, poisson, satMask, badMask);
     307        success &= pmReadoutGenerateMaskWeight(readout, poisson, satMask, badMask);
    308308    }
    309309
     
    311311}
    312312
     313
     314bool pmReadoutWeightRenorm(const pmReadout *readout, psMaskType maskVal, psStatsOptions meanStat,
     315                           psStatsOptions stdevStat, int width, psRandom *rng)
     316{
     317    PM_ASSERT_READOUT_NON_NULL(readout, false);
     318    PM_ASSERT_READOUT_IMAGE(readout, false);
     319    PM_ASSERT_READOUT_WEIGHT(readout, false);
     320    PS_ASSERT_INT_POSITIVE(width, false);
     321
     322    if (!psMemIncrRefCounter(rng)) {
     323        rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     324    }
     325
     326    psImage *image = readout->image, *mask = readout->mask, *weight = readout->weight; // Readout images
     327    int numCols = image->numCols, numRows = image->numRows; // Size of images
     328    int xNum = numCols / width + 1, yNum = numRows / width + 1; // Number of renormalisation regions
     329    float xSize = numCols / (float)xNum, ySize = numRows / (float)yNum; // Size of renormalisation regions
     330
     331    psStats *meanStats = psStatsAlloc(meanStat), *stdevStats = psStatsAlloc(stdevStat); // Statistics
     332    psVector *buffer = NULL;
     333
     334    for (int j = 0; j < yNum; j++) {
     335        // Bounds in y
     336        int yMin = j * ySize;
     337        int yMax = (j + 1) * ySize;
     338        for (int i = 0; i < xNum; i++) {
     339            // Bounds in x
     340            int xMin = i * xSize;
     341            int xMax = (i + 1) * xSize;
     342
     343            psRegion region = psRegionSet(xMin, xMax, yMin, yMax); // Region of interest
     344            psImage *subImage = psImageSubset(image, region); // Sub-image of the image pixels
     345            psImage *subWeight = psImageSubset(weight, region); // Sub image of the weight pixels
     346            psImage *subMask = mask ? psImageSubset(mask, region) : NULL; // Sub-image of the mask pixels
     347
     348            if (!psImageBackground(stdevStats, &buffer, subImage, subMask, maskVal, rng) ||
     349                !psImageBackground(meanStats, &buffer, subWeight, subMask, maskVal, rng)) {
     350                // Nothing we can do about it, but don't want to keel over and die, so do our best to flag it.
     351                psString regionStr = psRegionToString(region); // String with region
     352                psWarning("Unable to measure statistics over %s", regionStr);
     353                psFree(regionStr);
     354                psErrorClear();
     355                psImageInit(subWeight, NAN);
     356                if (subMask) {
     357                    psImageInit(subMask, maskVal);
     358                }
     359            } else {
     360                float meanVar = psStatsGetValue(meanStats, meanStat); // Mean of variance map
     361                float stdev = psStatsGetValue(stdevStats, stdevStat); // Standard deviation of image
     362                psBinaryOp(subWeight, subWeight, "*", psScalarAlloc(PS_SQR(stdev) / meanVar, PS_TYPE_F32));
     363            }
     364
     365            psFree(subImage);
     366            psFree(subWeight);
     367            psFree(subMask);
     368        }
     369    }
     370    psFree(meanStats);
     371    psFree(stdevStats);
     372    psFree(rng);
     373    psFree(buffer);
     374
     375    return true;
     376}
Note: See TracChangeset for help on using the changeset viewer.