IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26332


Ignore:
Timestamp:
Dec 3, 2009, 12:20:59 PM (16 years ago)
Author:
eugene
Message:

add code to calculate norm separately from kernel coeffs

Location:
branches/eam_branches/20091201/psModules/src/imcombine
Files:
5 edited

Legend:

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

    r26047 r26332  
    462462{
    463463    psArray *preCalc = kernels->preCalc->data[index]; // Precalculated data
    464 #if 1
     464#if 0
    465465    // Convolving using separable convolution
    466466    psVector *xKernel = preCalc->data[0]; // Kernel in x
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c

    r26330 r26332  
    2626
    2727// Calculate the least-squares matrix and vector
     28// XXX why are we calculating these values on each iteration?  aren't they identical (no change in pixel values...)
    2829static bool calculateMatrixVector(psImage *matrix, // Least-squares matrix, updated
    2930                                  psVector *vector, // Least-squares vector, updated
     
    3637                                  const psImage *polyValues, // Spatial polynomial values
    3738                                  int footprint, // (Half-)Size of stamp
    38                                   const bool normOnly
     39                                  const pmSubtractionEquationCalculationMode mode
    3940                                  )
    4041{
     
    5455
    5556    // Evaluate polynomial-polynomial terms
    56     // XXX we can skip this for normOnly
     57    // XXX we can skip this if we are not calculating kernel coeffs
    5758    for (int iyOrder = 0, iIndex = 0; iyOrder <= spatialOrder; iyOrder++) {
    5859        for (int ixOrder = 0; ixOrder <= spatialOrder - iyOrder; ixOrder++, iIndex++) {
     
    6869    }
    6970
    70 
    71     // if we only want to calculate the normalization (and background model?)
    72     // then we should assign these values in the matrix and vector to 1 (diagonal) or 0 (off-diagonal)
    73     // XXX need to disable normalization calculation if !normOnly
    74     if (normOnly) {
    75         psImageInit(matrix, 0.0);
    76         psVectorInit(vector, 1.0);
    77         for (int i = 0; i < matrix->numCols; i++) {
    78             matrix->data.F64[i][i] = 1.0;
    79         }
    80     } else {
    81         for (int i = 0; i < numKernels; i++) {
    82             psKernel *iConv = convolutions->data[i]; // Convolution for index i
    83             for (int j = i; j < numKernels; j++) {
    84                 psKernel *jConv = convolutions->data[j]; // Convolution for index j
    85 
    86                 double sumCC = 0.0;         // Sum of convolution products
    87                 for (int y = - footprint; y <= footprint; y++) {
    88                     for (int x = - footprint; x <= footprint; x++) {
    89                         double cc = iConv->kernel[y][x] * jConv->kernel[y][x];
    90 #ifdef USE_WEIGHT
     71    // initialize the matrix and vector for NOP on all coeffs.  we only fill in the coeffs we
     72    // choose to calculate
     73    psImageInit(matrix, 0.0);
     74    psVectorInit(vector, 1.0);
     75    for (int i = 0; i < matrix->numCols; i++) {
     76        matrix->data.F64[i][i] = 1.0;
     77    }
     78
     79    // the order of the elements in the matrix and vector is:
     80    // [kernel 0, x^0 y^0][kernel 1 x^0 y^0]...[kernel N, x^0 y^0]
     81    // [kernel 0, x^1 y^0][kernel 1 x^1 y^0]...[kernel N, x^1 y^0]
     82    // [kernel 0, x^n y^m][kernel 1 x^n y^m]...[kernel N, x^n y^m]
     83    // normalization
     84    // bg 0, bg 1, bg 2 (only 0 is currently used?)
     85
     86    for (int i = 0; i < numKernels; i++) {
     87        psKernel *iConv = convolutions->data[i]; // Convolution for index i
     88        for (int j = i; j < numKernels; j++) {
     89            psKernel *jConv = convolutions->data[j]; // Convolution for index j
     90
     91            double sumCC = 0.0;         // Sum of convolution products
     92            for (int y = - footprint; y <= footprint; y++) {
     93                for (int x = - footprint; x <= footprint; x++) {
     94                    double cc = iConv->kernel[y][x] * jConv->kernel[y][x];
     95                    if (weight) {
    9196                        cc *= weight->kernel[y][x];
    92 #endif
    93 #ifdef USE_WINDOW
    94                         if (window) {
    95                             cc *= window->kernel[y][x];
    96                         }
    97 #endif
    98                         sumCC += cc;
    9997                    }
     98                    if (window) {
     99                        cc *= window->kernel[y][x];
     100                    }
     101                    sumCC += cc;
    100102                }
    101 
    102                 // Spatial variation
     103            }
     104
     105            // Spatial variation of kernel coeffs
     106            if (mode | PM_SUBTRACTION_EQUATION_KERNELS) {
    103107                for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) {
    104108                    for (int jTerm = 0, jIndex = j; jTerm < numPoly; jTerm++, jIndex += numKernels) {
     
    109113                }
    110114            }
    111 
    112             double sumRC = 0.0;             // Sum of the reference-convolution products
    113             double sumIC = 0.0;             // Sum of the input-convolution products
    114             double sumC = 0.0;              // Sum of the convolution
    115             for (int y = - footprint; y <= footprint; y++) {
    116                 for (int x = - footprint; x <= footprint; x++) {
    117                     float conv = iConv->kernel[y][x];
    118                     float in = input->kernel[y][x];
    119                     float ref = reference->kernel[y][x];
    120                     double ic = in * conv;
    121                     double rc = ref * conv;
    122                     double c = conv;
    123 #ifdef USE_WEIGHT
     115        }
     116
     117        double sumRC = 0.0;             // Sum of the reference-convolution products
     118        double sumIC = 0.0;             // Sum of the input-convolution products
     119        double sumC = 0.0;              // Sum of the convolution
     120        for (int y = - footprint; y <= footprint; y++) {
     121            for (int x = - footprint; x <= footprint; x++) {
     122                float conv = iConv->kernel[y][x];
     123                float in = input->kernel[y][x];
     124                float ref = reference->kernel[y][x];
     125                double ic = in * conv;
     126                double rc = ref * conv;
     127                double c = conv;
     128                if (weight) {
    124129                    float wtVal = weight->kernel[y][x];
    125130                    ic *= wtVal;
    126131                    rc *= wtVal;
    127132                    c *= wtVal;
    128 #endif
    129 #ifdef USE_WINDOW
    130                     if (window) {
    131                         float winVal = window->kernel[y][x];
    132                         ic *= winVal;
    133                         rc *= winVal;
    134                         c  *= winVal;
    135                     }
    136 #endif
    137                     sumIC += ic;
    138                     sumRC += rc;
    139                     sumC += c;
    140133                }
     134                if (window) {
     135                    float winVal = window->kernel[y][x];
     136                    ic *= winVal;
     137                    rc *= winVal;
     138                    c  *= winVal;
     139                }
     140                sumIC += ic;
     141                sumRC += rc;
     142                sumC += c;
    141143            }
    142             // Spatial variation
    143             for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) {
    144                 double normTerm = sumRC * poly[iTerm];
    145                 double bgTerm = sumC * poly[iTerm];
     144        }
     145        // Spatial variation
     146        for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) {
     147            double normTerm = sumRC * poly[iTerm];
     148            double bgTerm = sumC * poly[iTerm];
     149            if ((mode | PM_SUBTRACTION_EQUATION_NORM) && (mode | PM_SUBTRACTION_EQUATION_KERNELS)) {
    146150                matrix->data.F64[iIndex][normIndex] = normTerm;
    147151                matrix->data.F64[normIndex][iIndex] = normTerm;
     152            }
     153            if ((mode | PM_SUBTRACTION_EQUATION_BG) && (mode | PM_SUBTRACTION_EQUATION_KERNELS)) {
    148154                matrix->data.F64[iIndex][bgIndex] = bgTerm;
    149155                matrix->data.F64[bgIndex][iIndex] = bgTerm;
     156            }
     157            if (mode | PM_SUBTRACTION_EQUATION_KERNELS) {
    150158                vector->data.F64[iIndex] = sumIC * poly[iTerm];
    151159            }
    152160        }
    153161    }
    154 
    155     // XXX need to disable normalization calculation if !normOnly
    156162
    157163    double sumRR = 0.0;                 // Sum of the reference product
     
    167173            double rr = PS_SQR(ref);
    168174            double one = 1.0;
    169 #ifdef USE_WEIGHT
    170             float wtVal = weight->kernel[y][x];
    171             rr *= wtVal;
    172             ir *= wtVal;
    173             in *= wtVal;
    174             ref *= wtVal;
    175             one *= wtVal;
    176 #endif
    177 #ifdef USE_WINDOW
     175            if (weight) {
     176                float wtVal = weight->kernel[y][x];
     177                rr *= wtVal;
     178                ir *= wtVal;
     179                in *= wtVal;
     180                ref *= wtVal;
     181                one *= wtVal;
     182            }
    178183            if (window) {
    179184                float  winVal = window->kernel[y][x];
     
    184189                one *= winVal;
    185190            }
    186 #endif
    187191            sumRR += rr;
    188192            sumIR += ir;
     
    192196        }
    193197    }
    194     matrix->data.F64[normIndex][normIndex] = sumRR;
    195     matrix->data.F64[bgIndex][bgIndex] = sum1;
    196     matrix->data.F64[normIndex][bgIndex] = matrix->data.F64[bgIndex][normIndex] = sumR;
    197     vector->data.F64[normIndex] = sumIR;
    198     vector->data.F64[bgIndex] = sumI;
    199 
     198    if (mode | PM_SUBTRACTION_EQUATION_NORM) {
     199        matrix->data.F64[normIndex][normIndex] = sumRR;
     200        vector->data.F64[normIndex] = sumIR;
     201    }
     202    if (mode | PM_SUBTRACTION_EQUATION_BG) {
     203        matrix->data.F64[bgIndex][bgIndex] = sum1;
     204        vector->data.F64[bgIndex] = sumI;
     205    }
     206    if ((mode | PM_SUBTRACTION_EQUATION_NORM) && (mode | PM_SUBTRACTION_EQUATION_BG)) {
     207        matrix->data.F64[normIndex][bgIndex] = sumR;
     208        matrix->data.F64[bgIndex][normIndex] = sumR;
     209    }
    200210    return true;
    201211}
     
    267277                    double bb = iConv2->kernel[y][x] * jConv2->kernel[y][x];
    268278                    double ab = iConv1->kernel[y][x] * jConv2->kernel[y][x];
    269 #ifdef USE_WEIGHT
    270                     float wtVal = weight->kernel[y][x];
    271                     aa *= wtVal;
    272                     bb *= wtVal;
    273                     ab *= wtVal;
    274 #endif
     279                    if (weight) {
     280                        float wtVal = weight->kernel[y][x];
     281                        aa *= wtVal;
     282                        bb *= wtVal;
     283                        ab *= wtVal;
     284                    }
    275285                    sumAA += aa;
    276286                    sumBB += bb;
     
    299309                for (int x = - footprint; x <= footprint; x++) {
    300310                    double ab = iConv1->kernel[y][x] * jConv2->kernel[y][x];
    301 #ifdef USE_WEIGHT
    302                     ab *= weight->kernel[y][x];
    303 #endif
     311                    if (weight) {
     312                        ab *= weight->kernel[y][x];
     313                    }
    304314                    sumAB += ab;
    305315                }
     
    336346                double i1i2 = i1 * i2;
    337347
    338 #ifdef USE_WEIGHT
    339                 float wtVal = weight->kernel[y][x];
    340                 ai2 *= wtVal;
    341                 bi2 *= wtVal;
    342                 ai1 *= wtVal;
    343                 bi1 *= wtVal;
    344                 i1i2 *= wtVal;
    345                 a *= wtVal;
    346                 b *= wtVal;
    347                 i2 *= wtVal;
    348 #endif
    349 
     348                if (weight) {
     349                    float wtVal = weight->kernel[y][x];
     350                    ai2 *= wtVal;
     351                    bi2 *= wtVal;
     352                    ai1 *= wtVal;
     353                    bi1 *= wtVal;
     354                    i1i2 *= wtVal;
     355                    a *= wtVal;
     356                    b *= wtVal;
     357                    i2 *= wtVal;
     358                }
    350359                sumAI2 += ai2;
    351360                sumBI2 += bi2;
     
    392401            double i1i2 = i1 * i2;
    393402
    394 #ifdef USE_WEIGHT
    395             float wtVal = weight->kernel[y][x];
    396             i1 *= wtVal;
    397             i1i1 *= wtVal;
    398             one *= wtVal;
    399             i2 *= wtVal;
    400             i1i2 *= wtVal;
    401 #endif
    402 
     403            if (weight) {
     404                float wtVal = weight->kernel[y][x];
     405                i1 *= wtVal;
     406                i1i1 *= wtVal;
     407                one *= wtVal;
     408                i2 *= wtVal;
     409                i1i2 *= wtVal;
     410            }
    403411            sumI1 += i1;
    404412            sumI1I1 += i1i1;
     
    588596    const pmSubtractionKernels *kernels = job->args->data[1]; // Kernels
    589597    int index = PS_SCALAR_VALUE(job->args->data[2], S32); // Stamp index
    590 
    591     return pmSubtractionCalculateEquationStamp(stamps, kernels, index, normOnly);
     598    pmSubtractionEquationCalculationMode mode  = PS_SCALAR_VALUE(job->args->data[3], S32); // calculation model
     599
     600    return pmSubtractionCalculateEquationStamp(stamps, kernels, index, mode);
    592601}
    593602
    594603bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels,
    595                                          int index, bool normOnly)
     604                                         int index, const pmSubtractionEquationCalculationMode mode)
    596605{
    597606    PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);
     
    662671
    663672    bool status;                    // Status of least-squares matrix/vector calculation
     673
     674    psKernel *weight = NULL;
     675    psKernel *window = NULL;
     676
     677#ifdef USE_WEIGHT
     678    weight = stamp->weight;
     679#endif
     680#ifdef USE_WINDOW
     681    window = stamps->window;
     682#endif
     683
    664684    switch (kernels->mode) {
    665685      case PM_SUBTRACTION_MODE_1:
    666686        status = calculateMatrixVector(stamp->matrix1, stamp->vector1, stamp->image2, stamp->image1,
    667                                        stamp->weight, stamps->window, stamp->convolutions1, kernels,
    668                                        polyValues, footprint, normOnly);
     687                                       weight, window, stamp->convolutions1, kernels,
     688                                       polyValues, footprint, mode);
    669689        break;
    670690      case PM_SUBTRACTION_MODE_2:
    671691        status = calculateMatrixVector(stamp->matrix1, stamp->vector1, stamp->image1, stamp->image2,
    672                                        stamp->weight, stamps->window, stamp->convolutions2, kernels,
    673                                        polyValues, footprint, normOnly);
     692                                       weight, window, stamp->convolutions2, kernels,
     693                                       polyValues, footprint, mode);
    674694        break;
    675695      case PM_SUBTRACTION_MODE_DUAL:
    676         psAbort ("dual is disabled: need to add window and normOnly");
     696        psAbort ("dual is disabled: need to add window and calculation mode");
    677697        if (new) {
    678698            stamp->matrix2 = psImageAlloc(numKernels * numSpatial, numKernels * numSpatial, PS_TYPE_F64);
     
    686706#endif
    687707        status = calculateDualMatrixVector(stamp->matrix1, stamp->vector1, stamp->matrix2, stamp->vector2,
    688                                            stamp->matrixX, stamp->image1, stamp->image2, stamp->weight,
     708                                           stamp->matrixX, stamp->image1, stamp->image2, weight,
    689709                                           stamp->convolutions1, stamp->convolutions2, kernels, polyValues,
    690710                                           footprint);
     
    758778}
    759779
    760 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, const bool normOnly)
     780bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, const pmSubtractionEquationCalculationMode mode)
    761781{
    762782    PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false);
     
    778798            psArrayAdd(job->args, 1, (pmSubtractionKernels*)kernels); // Casting away const to put on array
    779799            PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32);
    780             PS_ARRAY_ADD_SCALAR(job->args, normOnly, PS_TYPE_BOOL);
     800            PS_ARRAY_ADD_SCALAR(job->args, mode, PS_TYPE_S32);
    781801            if (!psThreadJobAddPending(job)) {
    782802                psFree(job);
     
    785805            psFree(job);
    786806        } else {
    787             pmSubtractionCalculateEquationStamp(stamps, kernels, i, normOnly);
     807            pmSubtractionCalculateEquationStamp(stamps, kernels, i, mode);
    788808        }
    789809    }
     
    803823}
    804824
    805 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps)
     825bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels,
     826                                const pmSubtractionStampList *stamps,
     827                                const pmSubtractionEquationCalculationMode mode)
    806828{
    807829    PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, false);
     
    941963            return NULL;
    942964        }
    943         kernels->solution1 = psMatrixLUSolution(kernels->solution1, luMatrix, sumVector, permutation);
     965
     966        psVector *solution = psMatrixLUSolution(NULL, luMatrix, sumVector, permutation);
     967        psFree(sumVector);
     968        psFree(luMatrix);
     969        psFree(permutation);
     970        if (!solution) {
     971            psError(PS_ERR_UNKNOWN, true, "Failed to solve the least-squares system.\n");
     972            return NULL;
     973        }
     974
     975        if (!kernels->solution1) {
     976            kernels->solution1 = psVectorAlloc (sumVector->n, PS_TYPE_F64);
     977            psVectorInit (kernels->solution1, 0.0);
     978        }
     979
     980        // only update the solutions that we chose to calculate:
     981        if (mode | PM_SUBTRACTION_EQUATION_NORM) {
     982            int normIndex = PM_SUBTRACTION_INDEX_NORM(kernels); // Index for normalisation
     983            kernels->solution1->data.F64[normIndex] = solution->data.F64[normIndex];
     984        }
     985        if (mode | PM_SUBTRACTION_EQUATION_BG) {
     986            int bgIndex = PM_SUBTRACTION_INDEX_BG(kernels); // Index in matrix for background
     987            kernels->solution1->data.F64[bgIndex] = solution->data.F64[bgIndex];
     988        }
     989        if (mode | PM_SUBTRACTION_EQUATION_KERNELS) {
     990            int numKernels = kernels->num;
     991            int spatialOrder = kernels->spatialOrder;       // Order of spatial variation
     992            int numPoly = PM_SUBTRACTION_POLYTERMS(spatialOrder); // Number of polynomial terms
     993            for (int i = 0; i < numKernels * numPoly; i++) {
     994                kernels->solution1->data.F64[i] = solution->data.F64[i];
     995            }
     996        }
     997        psFree (solution);
    944998
    945999#ifdef TESTING
     
    9521006#endif
    9531007
    954         psFree(sumVector);
    955         psFree(luMatrix);
    956         psFree(permutation);
    957         if (!kernels->solution1) {
    958             psError(PS_ERR_UNKNOWN, true, "Failed to solve the least-squares system.\n");
    959             return NULL;
    960         }
    9611008    } else {
    9621009        // Dual convolution solution
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.h

    r26330 r26332  
    44#include "pmSubtractionStamps.h"
    55#include "pmSubtractionKernels.h"
     6
     7typedef enum {
     8    PM_SUBTRACTION_EQUATION_NONE    = 0x00,
     9    PM_SUBTRACTION_EQUATION_NORM    = 0x01,
     10    PM_SUBTRACTION_EQUATION_BG      = 0x02,
     11    PM_SUBTRACTION_EQUATION_KERNELS = 0x04,
     12    PM_SUBTRACTION_EQUATION_ALL     = 0x05, // value should be NORM | BG | KERNELS
     13} pmSubtractionEquationCalculationMode;
    614
    715/// Execute a thread job to calculate the least-squares equation for a stamp
     
    1321                                         const pmSubtractionKernels *kernels, ///< Kernel parameters
    1422                                         int index, ///< Index of stamp
    15                                          const bool normOnly
    16                                     );
     23                                         const pmSubtractionEquationCalculationMode mode
     24    );
    1725
    1826/// Calculate the least-squares equation to match the image quality
    1927bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps
    2028                                    const pmSubtractionKernels *kernels, ///< Kernel parameters
    21                                     const bool normOnly
    22                                     );
     29                                    const pmSubtractionEquationCalculationMode mode
     30    );
    2331
    2432/// Solve the least-squares equation to match the image quality
    2533bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, ///< Kernel parameters
    26                                 const pmSubtractionStampList *stamps ///< Stamps
     34                                const pmSubtractionStampList *stamps, ///< Stamps
     35                                const pmSubtractionEquationCalculationMode mode
    2736    );
    2837
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.c

    r26330 r26332  
    561561
    562562                // XXX step 1: calculate normalization
    563                 psTrace("psModules.imcombine", 3, "Calculating equation...\n");
    564                 if (!pmSubtractionCalculateEquation(stamps, kernels, true)) {
     563                psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
     564                // if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_NORM)) {
     565                if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_ALL)) {
    565566                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    566567                    goto MATCH_ERROR;
    567568                }
    568569
    569                 // XXX step 2: calculate only other parameters
     570                psTrace("psModules.imcombine", 3, "Solving equation for normalization...\n");
     571                // if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_NORM)) {
     572                if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_ALL)) {
     573                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     574                    goto MATCH_ERROR;
     575                }
     576                memCheck("  solve equation");
     577
    570578# if (0)
    571                 psTrace("psModules.imcombine", 3, "Calculating equation...\n");
    572                 if (!pmSubtractionCalculateEquation(stamps, kernels)) {
     579                // XXX step 2: calculate kernel parameters
     580                psTrace("psModules.imcombine", 3, "Calculating equation for kernels...\n");
     581                if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
    573582                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    574583                    goto MATCH_ERROR;
    575584                }
     585                memCheck("  calculate equation");
     586
     587                psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
     588                if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
     589                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     590                    goto MATCH_ERROR;
     591                }
     592                memCheck("  solve equation");
    576593# endif
    577 
    578                 memCheck("  calculate equation");
    579 
    580                 psTrace("psModules.imcombine", 3, "Solving equation...\n");
    581 
    582                 if (!pmSubtractionSolveEquation(kernels, stamps)) {
    583                     psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    584                     goto MATCH_ERROR;
    585                 }
    586 
    587                 memCheck("  solve equation");
    588594
    589595                psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
     
    609615            // if we hit the max number of iterations and we have rejected stamps, re-solve
    610616            if (numRejected > 0) {
    611                 psTrace("psModules.imcombine", 3, "Solving equation...\n");
    612                 if (!pmSubtractionSolveEquation(kernels, stamps)) {
     617                // calculate kernel parameters
     618                psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
     619                // if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
     620                if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_ALL)) {
    613621                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    614622                    goto MATCH_ERROR;
    615623                }
     624                memCheck("  solve equation");
     625
    616626                psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
    617627                if (!deviations) {
     
    918928    assert(kernels);
    919929
    920     psTrace("psModules.imcombine", 3, "Calculating %s equation...\n", description);
    921     if (!pmSubtractionCalculateEquation(stamps, kernels)) {
     930    psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);
     931    // if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_NORM)) {
     932    if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_ALL)) {
    922933        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    923934        return false;
    924935    }
    925936
    926     psTrace("psModules.imcombine", 3, "Solving %s equation...\n", description);
    927     if (!pmSubtractionSolveEquation(kernels, stamps)) {
     937    psTrace("psModules.imcombine", 3, "Solving %s normalization equation...\n", description);
     938    // if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_NORM)) {
     939    if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_ALL)) {
    928940        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    929941        return false;
    930942    }
     943
     944# if (0)
     945    psTrace("psModules.imcombine", 3, "Calculating %s kernel coeffs equation...\n", description);
     946    if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
     947        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     948        return false;
     949    }
     950
     951    psTrace("psModules.imcombine", 3, "Solving %s kernel coeffs equation...\n", description);
     952    if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
     953        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
     954        return false;
     955    }
     956# endif
    931957
    932958    psTrace("psModules.imcombine", 3, "Calculate %s deviations...\n", description);
     
    949975        // Allow re-fit with reduced stamps set
    950976        psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description);
    951         if (!pmSubtractionSolveEquation(kernels, stamps)) {
     977        // if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
     978        if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_ALL)) {
    952979            psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
    953980            return false;
    954981        }
    955982        psTrace("psModules.imcombine", 3, "Recalculate %s deviations...\n", description);
     983
    956984        psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
    957985        if (!deviations) {
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionVisual.c

    r26318 r26332  
    263263static psImage *targetImage      = NULL;
    264264static psImage *residualImage    = NULL;
     265static psImage *fresidualImage   = NULL;
    265266static psImage *differenceImage  = NULL;
    266267static psImage *convolutionImage = NULL;
     
    289290    targetImage      = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
    290291    residualImage    = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     292    fresidualImage   = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
    291293    differenceImage  = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
    292294    convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
     
    295297    psImageInit (targetImage,      0.0);
    296298    psImageInit (residualImage,    0.0);
     299    psImageInit (fresidualImage,   0.0);
    297300    psImageInit (differenceImage,  0.0);
    298301    psImageInit (convolutionImage, 0.0);
     
    343346        for (int x = -footprint; x <= footprint; x++) {
    344347            residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm + convolution->kernel[y][x];
     348        }
     349    }
     350
     351    // insert the (fresidual) kernel into the (fresidual) image:
     352    for (int y = -footprint; y <= footprint; y++) {
     353        for (int x = -footprint; x <= footprint; x++) {
     354            fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / target->kernel[y][x];
    345355        }
    346356    }
     
    358368    pmVisualScaleImage(kapa1, convolutionImage, "Convolution Stamps", 2, true);
    359369
     370    // pmVisualScaleImage(kapa2, fresidualImage, "Frac Residual Stamps", 2, true);
     371    pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true);
    360372    pmVisualScaleImage(kapa2, differenceImage, "Difference Stamps", 0, true);
    361     pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true);
    362373    pmVisualAskUser(NULL);
    363374
     
    367378    psFree(differenceImage);
    368379    psFree(residualImage);
     380    psFree(fresidualImage);
    369381
    370382    targetImage = NULL;
     
    373385    differenceImage = NULL;
    374386    residualImage = NULL;
     387    fresidualImage = NULL;
    375388
    376389    return true;
Note: See TracChangeset for help on using the changeset viewer.