IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 29, 2010, 6:02:38 PM (16 years ago)
Author:
Paul Price
Message:

Fairly extensive change to make subtractions more stable on images with limited lit area in the presence of spatial variation. Took the polynomials which were scaled over the entire image and scale them only over the lit area. Removed some fprintf statements. Fixed the problem causing the background term to always come out 1.0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.c

    r26733 r26739  
    7070                                 const psImage *subMask, // Mask for subtraction, or NULL
    7171                                 psImage *variance,  // Variance map
    72                                  const psRegion *region, // Region of interest, or NULL
     72                                 const psRegion *region, // Region of interest
    7373                                 float thresh1,  // Threshold for stamp finding on readout 1
    7474                                 float thresh2,  // Threshold for stamp finding on readout 2
     
    8282    )
    8383{
     84    PS_ASSERT_PTR_NON_NULL(stamps, false);
     85    PM_ASSERT_READOUT_NON_NULL(ro1, false);
     86    PM_ASSERT_READOUT_NON_NULL(ro2, false);
     87    PS_ASSERT_IMAGE_NON_NULL(subMask, false);
     88    PS_ASSERT_IMAGE_NON_NULL(variance, false);
     89    PS_ASSERT_PTR_NON_NULL(region, false);
     90
    8491    psTrace("psModules.imcombine", 3, "Finding stamps...\n");
    8592
     
    96103
    97104    psTrace("psModules.imcombine", 3, "Extracting stamps...\n");
    98     if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, variance, size)) {
     105    if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2->image, variance, size, *region)) {
    99106        psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps.");
    100107        return false;
     
    319326    pmSubtractionMaskInvalid(ro2, maskVal);
    320327
    321     psImage *subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, 0,
     328    psRegion bounds = psRegionSet(NAN, NAN, NAN, NAN); // Bounds of valid pixels
     329
     330    psImage *subMask = pmSubtractionMask(&bounds, ro1, ro2, maskVal, size, 0,
    322331                                         badFrac, mode); // Subtraction mask
    323332    if (!subMask) {
     
    441450    // Putting important variable declarations here, since they are freed after a "goto" if there is an error.
    442451    psImage *subMask = NULL;            // Mask for subtraction
    443     psRegion *region = NULL;            // Iso-kernel region
     452    psRegion *region = psRegionAlloc(NAN, NAN, NAN, NAN); // Iso-kernel region
    444453    psString regionString = NULL;       // String for region
    445454    pmSubtractionStampList *stamps = NULL; // Stamps for matching PSF
     
    457466    pmSubtractionMaskInvalid(ro2, maskVal);
    458467
    459     subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, footprint,
    460                                 badFrac, subMode);
     468    psRegion bounds = psRegionSet(NAN, NAN, NAN, NAN); // Bounds of valid pixels
     469
     470    subMask = pmSubtractionMask(&bounds, ro1, ro2, maskVal, size, footprint, badFrac, subMode);
    461471    if (!subMask) {
    462472        psError(psErrorCodeLast(), false, "Unable to generate subtraction mask.");
     
    468478    // Get region of interest
    469479    int xRegions = 1, yRegions = 1;     // Number of iso-kernel regions
    470     float xRegionSize = 0, yRegionSize = 0; // Size of iso-kernel regions
     480    float xRegionSize = NAN, yRegionSize = NAN; // Size of iso-kernel regions
    471481    if (isfinite(regionSize) && regionSize != 0.0) {
    472         xRegions = numCols / regionSize + 1;
    473         yRegions = numRows / regionSize + 1;
    474         xRegionSize = (float)numCols / (float)xRegions;
    475         yRegionSize = (float)numRows / (float)yRegions;
    476         region = psRegionAlloc(NAN, NAN, NAN, NAN);
     482        xRegions = (bounds.x1 - bounds.x0) / regionSize + 1;
     483        yRegions = (bounds.y1 - bounds.y0) / regionSize + 1;
     484        xRegionSize = (float)(bounds.x1 - bounds.x0) / (float)xRegions;
     485        yRegionSize = (float)(bounds.y1 - bounds.y0) / (float)yRegions;
     486    } else {
     487        xRegionSize = bounds.x1 - bounds.x0;
     488        yRegionSize = bounds.y1 - bounds.y0;
    477489    }
    478490
     
    480492    float stampThresh1 = NAN, stampThresh2 = NAN; // Stamp thresholds for images
    481493    {
    482         psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for backgroun
     494        psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for background
    483495        if (ro1) {
    484496            psStatsInit(bg);
     
    504516    }
    505517
     518    // Just in case the iso-kernel region doesn't cover the entire image...
     519    if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_UNSURE ||
     520        subMode == PM_SUBTRACTION_MODE_DUAL) {
     521        if (!conv1->image) {
     522            conv1->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     523        }
     524        psImageInit(conv1->image, NAN);
     525        if (ro1->variance) {
     526            if (!conv1->variance) {
     527                conv1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     528            }
     529            psImageInit(conv1->variance, NAN);
     530        }
     531        if (subMask) {
     532            if (!conv1->mask) {
     533                conv1->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     534            }
     535            psImageInit(conv1->mask, maskBad);
     536        }
     537    }
     538    if (subMode == PM_SUBTRACTION_MODE_1 || subMode == PM_SUBTRACTION_MODE_UNSURE ||
     539        subMode == PM_SUBTRACTION_MODE_DUAL) {
     540        if (!conv2->image) {
     541            conv2->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     542        }
     543        psImageInit(conv2->image, NAN);
     544        if (ro2->variance) {
     545            if (!conv2->variance) {
     546                conv2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     547            }
     548            psImageInit(conv2->variance, NAN);
     549        }
     550        if (subMask) {
     551            if (!conv2->mask) {
     552                conv2->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     553            }
     554            psImageInit(conv2->mask, maskBad);
     555        }
     556    }
     557
     558
    506559    // Iterate over iso-kernel regions
    507560    for (int j = 0; j < yRegions; j++) {
     
    509562            psTrace("psModules.imcombine", 1, "Subtracting region %d of %d...\n",
    510563                    j * xRegions + i + 1, xRegions * yRegions);
    511             if (region) {
    512                 *region = psRegionSet((int)(i * xRegionSize), (int)((i + 1) * xRegionSize),
    513                                       (int)(j * yRegionSize), (int)((j + 1) * yRegionSize));
    514                 psFree(regionString);
    515                 regionString = psRegionToString(*region);
    516                 psTrace("psModules.imcombine", 3, "Iso-kernel region: %s out of %d,%d\n",
    517                         regionString, numCols, numRows);
    518             }
     564            *region = psRegionSet(bounds.x0 + (int)(i * xRegionSize),
     565                                  bounds.x0 + (int)((i + 1) * xRegionSize),
     566                                  bounds.y0 + (int)(j * yRegionSize),
     567                                  bounds.y0 + (int)((j + 1) * yRegionSize));
     568            psFree(regionString);
     569            regionString = psRegionToString(*region);
     570            psLogMsg("psModules.imcombine", PS_LOG_DETAIL, "Iso-kernel region: %s out of %d,%d\n",
     571                    regionString, numCols, numRows);
    519572
    520573            if (stampsName && strlen(stampsName) > 0) {
     
    530583            // We get the stamps here; we will also attempt to get stamps at the first iteration, but it
    531584            // doesn't matter.
    532             if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, NULL, stampThresh1, stampThresh2,
     585            if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, region, stampThresh1, stampThresh2,
    533586                                      stampSpacing, normFrac, sysError, skyError, size, footprint, subMode)) {
    534587                goto MATCH_ERROR;
     
    544597            // Define kernel basis functions
    545598            if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) {
    546                 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder,
    547                                                           stamps, footprint, optThreshold, penalty, subMode);
     599                kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder,
     600                                                          optFWHMs, optOrder, stamps, footprint,
     601                                                          optThreshold, penalty, bounds, subMode);
    548602                if (!kernels) {
    549603                    psErrorClear();
     
    554608                // Not an ISIS/GUNK kernel, or the optimum kernel search failed
    555609                kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders,
    556                                                        inner, binning, ringsOrder, penalty, subMode);
     610                                                       inner, binning, ringsOrder, penalty, bounds, subMode);
    557611                // pmSubtractionVisualShowKernels(kernels);
    558612            }
     
    603657                psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k);
    604658
    605 #if 0
    606659                if (!subtractionGetStamps(&stamps, ro1, ro2, subMask, variance, region,
    607660                                          stampThresh1, stampThresh2, stampSpacing, normFrac,
     
    609662                    goto MATCH_ERROR;
    610663                }
    611 #endif
    612664
    613665                // generate the window function from the set of stamps
Note: See TracChangeset for help on using the changeset viewer.