IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 6, 2007, 3:57:15 PM (18 years ago)
Author:
Paul Price
Message:

Implementing dual-convolution. This required reworking those
functions involved with calculating and solving the equations; moved
these into a separate file and made various other cleanups (e.g.,
assertions for pmSubtractionKernels). Removed the normalisation
(central pixel) term from all kernels, because this shouldn't be in
the second kernel (there's only one normalisation term between the two
kernels); the normalisation is treated explicitly in the equations,
along with the background (still only a constant background is
supported for now, but there's a lot of support for a polynomial
background for when I get around to putting it in the equations).
Tested the single convolution, and it's working; same results as
before, apparently. Haven't tested dual convolution yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r15447 r15756  
    1313#include "pmSubtractionKernels.h"
    1414#include "pmSubtractionStamps.h"
     15#include "pmSubtractionEquation.h"
    1516#include "pmSubtraction.h"
     17#include "pmSubtractionMask.h"
    1618#include "pmSubtractionMatch.h"
    1719
     20#define TOL 1.0e-3                      // Tolerance for subtraction solution
     21#define KERNEL_MOSAIC 2                 // Half-number of kernel instances in the mosaic image
    1822
    1923static bool useFFT = true;              // Do convolutions using FFT
     
    6367{
    6468    psTrace("psModules.imcombine", 3, "Finding stamps...\n");
    65     *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, stampSpacing, mode);
     69    *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, footprint,
     70                                      stampSpacing, mode);
    6671    if (!*stamps) {
    6772        psError(PS_ERR_UNKNOWN, false, "Unable to find stamps.");
     
    7277
    7378    psTrace("psModules.imcombine", 3, "Extracting stamps...\n");
    74     if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, weight, footprint, size)) {
     79    if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, weight, size)) {
    7580        psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps.");
    7681        return false;
     
    8691
    8792
    88 bool pmSubtractionMatch(pmReadout *convolved, const pmReadout *ro1, const pmReadout *ro2,
     93bool pmSubtractionMatch(pmReadout *conv1, pmReadout *conv2, const pmReadout *ro1, const pmReadout *ro2,
    8994                        int footprint, float regionSize, float stampSpacing, float threshold,
    9095                        const psArray *sources, const char *stampsName,
     
    95100                        psMaskType maskBlank, float badFrac, pmSubtractionMode mode)
    96101{
    97     PS_ASSERT_PTR_NON_NULL(convolved, false);
     102    PS_ASSERT_PTR_NON_NULL(conv1, false);
     103    if (mode == PM_SUBTRACTION_MODE_DUAL) {
     104        PS_ASSERT_PTR_NON_NULL(conv2, false);
     105    }
    98106    PS_ASSERT_PTR_NON_NULL(ro1, false);
    99107    PS_ASSERT_IMAGE_NON_NULL(ro1->image, false);
     
    174182
    175183    // Reset the output readout, just in case
    176     if (convolved->image) {
    177         psFree(convolved->image);
    178         convolved->image = NULL;
    179     }
    180     if (convolved->mask) {
    181         psFree(convolved->mask);
    182         convolved->mask = NULL;
    183     }
    184     if (convolved->weight) {
    185         psFree(convolved->weight);
    186         convolved->weight = NULL;
     184    if (conv1->image) {
     185        psFree(conv1->image);
     186        conv1->image = NULL;
     187    }
     188    if (conv1->mask) {
     189        psFree(conv1->mask);
     190        conv1->mask = NULL;
     191    }
     192    if (conv1->weight) {
     193        psFree(conv1->weight);
     194        conv1->weight = NULL;
    187195    }
    188196
     
    250258
    251259            if (sources) {
    252                 stamps = pmSubtractionStampsSetFromSources(sources, subMask, region, stampSpacing, mode);
     260                stamps = pmSubtractionStampsSetFromSources(sources, subMask, region, footprint,
     261                                                           stampSpacing, mode);
    253262            } else if (stampsName && strlen(stampsName) > 0) {
    254                 stamps = pmSubtractionStampsSetFromFile(stampsName, subMask, region, stampSpacing, mode);
     263                stamps = pmSubtractionStampsSetFromFile(stampsName, subMask, region, footprint,
     264                                                        stampSpacing, mode);
    255265            }
    256266
     
    295305                // Not an ISIS/GUNK kernel, or the optimum kernel search failed
    296306                kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders,
    297                                                        inner, binning, ringsOrder);
    298             }
    299             psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL",
     307                                                       inner, binning, ringsOrder, mode);
     308            }
     309            psMetadataAddPtr(conv1->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL",
    300310                             PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "Subtraction kernels", kernels);
    301311
     
    312322
    313323                psTrace("psModules.imcombine", 3, "Calculating equation...\n");
    314                 if (!pmSubtractionCalculateEquation(stamps, kernels, footprint, mode)) {
     324                if (!pmSubtractionCalculateEquation(stamps, kernels)) {
    315325                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    316326                    goto MATCH_ERROR;
     
    320330
    321331                psTrace("psModules.imcombine", 3, "Solving equation...\n");
    322                 solution = pmSubtractionSolveEquation(solution, stamps);
    323                 if (!solution) {
     332
     333                if (!pmSubtractionSolveEquation(kernels, stamps, TOL)) {
    324334                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    325335                    goto MATCH_ERROR;
     
    328338                memCheck("  solve equation");
    329339
    330                 psVector *deviations = pmSubtractionCalculateDeviations(stamps, solution, footprint, kernels,
    331                                                                         mode); // Deviations for each stamp
     340                psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
    332341                if (!deviations) {
    333342                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
     
    351360            if (numRejected > 0) {
    352361                psTrace("psModules.imcombine", 3, "Solving equation...\n");
    353                 solution = pmSubtractionSolveEquation(solution, stamps);
    354                 if (!solution) {
     362                if (!pmSubtractionSolveEquation(kernels, stamps, TOL)) {
    355363                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    356364                    goto MATCH_ERROR;
    357365                }
    358                 psVector *deviations = pmSubtractionCalculateDeviations(stamps, solution, footprint, kernels,
    359                                                                         mode); // Deviations for each stamp
     366                psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
    360367                if (!deviations) {
    361368                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
     
    376383                psImage *convKernels = psImageAlloc(5 * fullSize - 1, 5 * fullSize - 1, PS_TYPE_F32);
    377384                psImageInit(convKernels, NAN);
    378                 for (int j = -2; j <= 2; j++) {
    379                     for (int i = -2; i <= 2; i++) {
    380                         psImage *kernel = pmSubtractionKernelImage(solution, kernels, (float)i / 2.0,
    381                                                                    (float)j / 2.0); // Image of the kernel
     385                for (int j = -KERNEL_MOSAIC; j <= KERNEL_MOSAIC; j++) {
     386                    for (int i = -KERNEL_MOSAIC; i <= KERNEL_MOSAIC; i++) {
     387                        psImage *kernel = pmSubtractionKernelImage(kernels, (float)i / (float)KERNEL_MOSAIC,
     388                                                                   (float)j / (float)KERNEL_MOSAIC,
     389                                                                   false); // Image of the kernel
    382390                        if (!kernel) {
    383391                            psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image.");
     
    386394                        }
    387395
    388                         if (psImageOverlaySection(convKernels, kernel, (i + 2) * fullSize,
    389                                                   (j + 2) * fullSize, "=") == 0) {
     396                        if (psImageOverlaySection(convKernels, kernel, (i + KERNEL_MOSAIC) * fullSize,
     397                                                  (j + KERNEL_MOSAIC) * fullSize, "=") == 0) {
    390398                            psError(PS_ERR_UNKNOWN, false, "Unable to overlay kernel image.");
    391399                            psFree(kernel);
     
    399407                psString comment = NULL; // Comment for metadata
    400408                psStringAppend(&comment, "Subtraction kernel for region %s", regionString);
    401                 psMetadataAddImage(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL.IMAGE",
     409                psMetadataAddImage(conv1->analysis, PS_LIST_TAIL, "SUBTRACTION.KERNEL.IMAGE",
    402410                                   PS_META_DUPLICATE_OK, comment, convKernels);
    403411                psFree(comment);
     
    427435
    428436            psTrace("psModules.imcombine", 2, "Convolving...\n");
    429             if (!pmSubtractionConvolve(convolved, ro1, ro2, subMask, maskBlank, region,
    430                                        solution, kernels, mode, useFFT)) {
     437            if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, maskBlank, region, kernels, useFFT)) {
    431438                psError(PS_ERR_UNKNOWN, false, "Unable to convolve image.");
    432439                goto MATCH_ERROR;
     
    439446                psString comment = NULL; // Comment for metadata
    440447                psStringAppend(&comment, "Subtraction solution for region %s", regionString);
    441                 psMetadataAddVector(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.SOLUTION",
     448                psMetadataAddVector(conv1->analysis, PS_LIST_TAIL, "SUBTRACTION.SOLUTION",
    442449                                    PS_META_DUPLICATE_OK, comment, solution);
    443450                psFree(comment);
    444451                if (region) {
    445                     psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.REGION",
     452                    psMetadataAddPtr(conv1->analysis, PS_LIST_TAIL, "SUBTRACTION.REGION",
    446453                                     PS_META_DUPLICATE_OK | PS_DATA_REGION, comment, region);
    447454                } else {
    448455                    region = psRegionAlloc(0, numCols, 0, numRows);
    449                     psMetadataAddPtr(convolved->analysis, PS_LIST_TAIL, "SUBTRACTION.REGION",
     456                    psMetadataAddPtr(conv1->analysis, PS_LIST_TAIL, "SUBTRACTION.REGION",
    450457                                     PS_META_DUPLICATE_OK | PS_DATA_REGION, comment, region);
    451458                    psFree(region);
     
    458465
    459466            // There is data in the readout now
    460             convolved->data_exists = true;
    461             if (convolved->parent) {
    462                 convolved->parent->data_exists = true;
    463                 convolved->parent->parent->data_exists = true;
     467            conv1->data_exists = true;
     468            if (conv1->parent) {
     469                conv1->parent->data_exists = true;
     470                conv1->parent->parent->data_exists = true;
     471            }
     472            if (mode == PM_SUBTRACTION_MODE_DUAL) {
     473                conv2->data_exists = true;
     474                if (conv2->parent) {
     475                    conv2->parent->data_exists = true;
     476                    conv2->parent->parent->data_exists = true;
     477                }
    464478            }
    465479        }
     
    474488    weight = NULL;
    475489
    476     if (!pmSubtractionBorder(convolved->image, convolved->weight, convolved->mask, size, maskBlank)) {
     490    if (!pmSubtractionBorder(conv1->image, conv1->weight, conv1->mask, size, maskBlank)) {
    477491        psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
    478492        goto MATCH_ERROR;
Note: See TracChangeset for help on using the changeset viewer.