IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 17, 2009, 6:55:35 PM (17 years ago)
Author:
Paul Price
Message:

Working on more robust way of determining the image to convolve. Intend to attempt to measure the convolution kernel each way, and take the one that does the best job. This code is currently #if-ed out.

File:
1 edited

Legend:

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

    r25060 r25101  
    869869    return mode;
    870870}
     871
     872
     873#if 0
     874/// A list of stamps
     875typedef struct {
     876    long num;                           ///< Number of stamps
     877    psArray *stamps;                    ///< The stamps
     878    psArray *regions;                   ///< Regions for each stamp
     879    psArray *x, *y;                     ///< Coordinates for possible stamps (or NULL)
     880    psArray *flux;                      ///< Fluxes for possible stamps (or NULL)
     881    int footprint;                      ///< Half-size of stamps
     882} pmSubtractionStampList;
     883
     884/// A stamp for image subtraction
     885typedef struct {
     886    float x, y;                         ///< Position
     887    float flux;                         ///< Flux
     888    float xNorm, yNorm;                 ///< Normalised position
     889    psKernel *image1;                   ///< Reference image postage stamp
     890    psKernel *image2;                   ///< Input image postage stamp
     891    psKernel *variance;                 ///< Variance image postage stamp, or NULL
     892    psArray *convolutions1;             ///< Convolutions of image 1 for each kernel component, or NULL
     893    psArray *convolutions2;             ///< Convolutions of image 2 for each kernel component, or NULL
     894    psImage *matrix1, *matrix2;         ///< Least-squares matrices for each image, or NULL
     895    psImage *matrixX;                   ///< Cross-matrix (for mode DUAL), or NULL
     896    psVector *vector1, *vector2;        ///< Least-squares vectors for each image, or NULL
     897    pmSubtractionStampStatus status;    ///< Status of stamp
     898} pmSubtractionStamp;
     899
     900/// Kernels specification
     901typedef struct {
     902    pmSubtractionKernelsType type;      ///< Type of kernels --- allowing the use of multiple kernels
     903    psString description;               ///< Description of the kernel parameters
     904    long num;                           ///< Number of kernel components (not including the spatial ones)
     905    psVector *u, *v;                    ///< Offset (for POIS) or polynomial order (for ISIS)
     906    psVector *widths;                   ///< Gaussian FWHMs (ISIS)
     907    psVector *uStop, *vStop;            ///< Width of kernel element (SPAM,FRIES only)
     908    psArray *preCalc;                   ///< Array of images containing pre-calculated kernel (for ISIS)
     909    float penalty;                      ///< Penalty for wideness
     910    psVector *penalties;                ///< Penalty for each kernel component
     911    int size;                           ///< The half-size of the kernel
     912    int inner;                          ///< The size of an inner region
     913    int spatialOrder;                   ///< The spatial order of the kernels
     914    int bgOrder;                        ///< The order for the background fitting
     915    pmSubtractionMode mode;             ///< Mode for subtraction
     916    int numCols, numRows;               ///< Size of image (for normalisation), or zero to use image provided
     917    psVector *solution1, *solution2;    ///< Solution for the PSF matching
     918    // Quality information
     919    float mean, rms;                    ///< Mean and RMS of chi^2 from stamps
     920    int numStamps;                      ///< Number of good stamps
     921} pmSubtractionKernels;
     922
     923// Test a subtraction mode by performing a single iteration
     924static bool subtractionModeTest(pmSubtractionStampList *stamps, // Stamps to use to find best mode
     925                                pmSubtractionKernels *kernels, // Kernel description
     926                                const char *description // Description for trace
     927                                )
     928{
     929    assert(stamps);
     930    assert(kernels);
     931
     932    psTrace("psModules.imcombine", 3, "Calculating %s equation...\n", description);
     933    if (!pmSubtractionCalculateEquation(stamps, kernels)) {
     934        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     935        return false;
     936    }
     937
     938    psTrace("psModules.imcombine", 3, "Solving %s equation...\n", description);
     939    if (!pmSubtractionSolveEquation(kernels, stamps)) {
     940        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     941        kernels->mode = oldMode;
     942        return false;
     943    }
     944
     945    psTrace("psModules.imcombine", 3, "Calculate %s deviations...\n", description);
     946    psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
     947    if (!deviations) {
     948        psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
     949        return false;
     950    }
     951
     952    psTrace("psModules.imcombine", 3, "Rejecting %s stamps...\n", description);
     953    long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, rej, footprint);
     954    if (numRejected < 0) {
     955        psError(PS_ERR_UNKNOWN, false, "Unable to reject stamps.");
     956        psFree(deviations);
     957        return false;
     958    }
     959    psFree(deviations);
     960
     961    if (numRejected > 0) {
     962        psTrace("psModules.imcombine", 3, "Solving equation...\n");
     963        if (!pmSubtractionSolveEquation(kernels, stamps)) {
     964            psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     965            return false;
     966        }
     967        psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
     968        if (!deviations) {
     969            psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
     970            return false;
     971        }
     972        psFree(deviations);
     973    }
     974
     975    return true;
     976}
     977
     978
     979pmSubtractionMode pmSubtractionBestMode(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels)
     980{
     981    PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, PM_SUBTRACTION_MODE_ERR);
     982    PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, PM_SUBTRACTION_MODE_ERR);
     983
     984    // Copies of the inputs so we can try each way
     985    pmSubtractionStampList *stamps1 = pmSubtractionStampsListCopy(stamps);
     986    pmSubtractionStampList *stamps2 = pmSubtractionStampsListCopy(stamps);
     987
     988    pmSubtractionKernels *kernels1 = pmSubtractionKernelsCopy(kernels);
     989    pmSubtractionKernels *kernels2 = pmSubtractionKernelsCopy(kernels);
     990
     991    kernels1->mode = PM_SUBTRACTION_MODE_1;
     992    kernels2->mode = PM_SUBTRACTION_MODE_2;
     993
     994
     995    subtractionModeTest(stamps1, kernels1, "forward");
     996    subtractionModeTest(stamps2, kernels2, "backward");
     997
     998    // XXX Compare kernels1->mean, kernels2->mean
     999}
     1000
     1001#endif
Note: See TracChangeset for help on using the changeset viewer.