IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2010, 5:32:21 PM (16 years ago)
Author:
eugene
Message:

clean up the code to remove old test concepts; normalization is calculated up front; matrix equation does not include place-holder elements for background and norm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100823/psModules/src/imcombine/pmSubtractionMatch.c

    r29004 r29165  
    2828static bool useFFT = true;              // Do convolutions using FFT
    2929
    30 # define SEPARATE 0
    31 # if (SEPARATE)
    32 # define SUBMODE PM_SUBTRACTION_EQUATION_NORM
    33 # else
    3430# define SUBMODE PM_SUBTRACTION_EQUATION_ALL
    35 # endif
    3631
    3732//#define TESTING
     
    672667                kernels = pmSubtractionKernelsGenerate(type, size, spatialOrder, isisWidths, isisOrders,
    673668                                                       inner, binning, ringsOrder, penalty, bounds, subMode);
    674                 // pmSubtractionVisualShowKernels(kernels);
    675669            }
    676670
     
    678672
    679673            if (subMode == PM_SUBTRACTION_MODE_UNSURE) {
    680 #if 0
    681                 // Get backgrounds
    682                 psStats *bgStats = psStatsAlloc(BG_STAT); // Statistics for background
    683                 psVector *buffer = NULL;// Buffer for stats
    684                 if (!psImageBackground(bgStats, &buffer, ro1->image, ro1->mask, maskVal, rng)) {
    685                     psError(PM_ERR_DATA, false, "Unable to measure background of image 1.");
    686                     psFree(bgStats);
    687                     psFree(buffer);
    688                     goto MATCH_ERROR;
    689                 }
    690                 float bg1 = psStatsGetValue(bgStats, BG_STAT); // Background for image 1
    691                 if (!psImageBackground(bgStats, &buffer, ro2->image, ro2->mask, maskVal, rng)) {
    692                     psError(PM_ERR_DATA, false, "Unable to measure background of image 2.");
    693                     psFree(bgStats);
    694                     psFree(buffer);
    695                     goto MATCH_ERROR;
    696                 }
    697                 float bg2 = psStatsGetValue(bgStats, BG_STAT); // Background for image 2
    698                 psFree(bgStats);
    699                 psFree(buffer);
    700 
    701                 pmSubtractionMode newMode = pmSubtractionOrder(stamps, bg1, bg2); // Subtraction mode to use
    702 #endif
    703674                pmSubtractionMode newMode = pmSubtractionBestMode(&stamps, &kernels, subMask, rej);
    704675                switch (newMode) {
     
    732703                }
    733704
    734                 // XXX step 1: calculate normalization
    735                 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
     705                // step 0 : calculate the normalizations, pass along to the next steps via stamps->normValue
     706                psTrace("psModules.imcombine", 3, "Calculating normalization...\n");
     707                if (!pmSubtractionCalculateNormalization(stamps, kernels->mode)) {
     708                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
     709                    goto MATCH_ERROR;
     710                }
     711
     712                // step 1: generate the elements of the matrix equation Ax = B
     713                psTrace("psModules.imcombine", 3, "Calculating kernel equations...\n");
    736714                if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) {
    737715                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
     
    739717                }
    740718
    741                 psTrace("psModules.imcombine", 3, "Solving equation for normalization...\n");
     719                // step 2: solve the matrix equation Ax = B
     720                psTrace("psModules.imcombine", 3, "Solving kernel equations...\n");
    742721                if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) {
    743722                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
     
    746725                memCheck("  solve equation");
    747726
    748 # if (SEPARATE)
    749                 // set USED -> CALCULATE
    750                 pmSubtractionStampsResetStatus (stamps);
    751 
    752                 // XXX step 2: calculate kernel parameters
    753                 psTrace("psModules.imcombine", 3, "Calculating equation for kernels...\n");
    754                 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
    755                     psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    756                     goto MATCH_ERROR;
    757                 }
    758                 memCheck("  calculate equation");
    759 
    760                 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
    761                 if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
    762                     psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    763                     goto MATCH_ERROR;
    764                 }
    765                 memCheck("  solve equation");
    766 # endif
    767727                psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
    768728                if (!deviations) {
     
    770730                    goto MATCH_ERROR;
    771731                }
    772 
    773732                memCheck("   calculate deviations");
    774733
     
    787746            // if we hit the max number of iterations and we have rejected stamps, re-solve
    788747            if (numRejected > 0) {
    789                 // XXX step 1: calculate normalization
     748
     749                // step 1: generate the elements of the matrix equation Ax = B
    790750                psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
    791751                if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) {
     
    794754                }
    795755
    796                 // solve normalization
     756                // step 2: solve the matrix equation Ax = B
    797757                psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
    798758                if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) {
     
    801761                }
    802762
    803 # if (SEPARATE)
    804                 // set USED -> CALCULATE
    805                 pmSubtractionStampsResetStatus (stamps);
    806 
    807                 // XXX step 2: calculate kernel parameters
    808                 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
    809                 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
    810                     psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    811                     goto MATCH_ERROR;
    812                 }
    813 
    814                 // solve kernel parameters
    815                 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
    816                 if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
    817                     psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    818                     goto MATCH_ERROR;
    819                 }
    820                 memCheck("  solve equation");
    821 # endif
    822763                psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
    823764                if (!deviations) {
     
    837778                goto MATCH_ERROR;
    838779            }
    839 
    840780            memCheck("diag outputs");
    841781
     
    11341074    }
    11351075
    1136 # if (SEPARATE)
    1137     // set USED -> CALCULATE
    1138     pmSubtractionStampsResetStatus (stamps);
    1139 
    1140     psTrace("psModules.imcombine", 3, "Calculating %s kernel coeffs equation...\n", description);
    1141     if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
    1142         psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    1143         return false;
    1144     }
    1145 
    1146     psTrace("psModules.imcombine", 3, "Solving %s kernel coeffs equation...\n", description);
    1147     if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
    1148         psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    1149         return false;
    1150     }
    1151 # endif
    1152 
    11531076    psTrace("psModules.imcombine", 3, "Calculate %s deviations...\n", description);
    11541077    psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
     
    11811104        }
    11821105        psTrace("psModules.imcombine", 3, "Recalculate %s deviations...\n", description);
    1183 
    1184 # if (SEPARATE)
    1185         // set USED -> CALCULATE
    1186         pmSubtractionStampsResetStatus (stamps);
    1187 
    1188         psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);
    1189         if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
    1190             psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    1191             return false;
    1192         }
    1193 
    1194         psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description);
    1195         if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
    1196             psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
    1197             return false;
    1198         }
    1199         psTrace("psModules.imcombine", 3, "Recalculate %s deviations...\n", description);
    1200 # endif
    12011106
    12021107        psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
     
    13011206    PS_ASSERT_FLOAT_LARGER_THAN(scaleMax, scaleMin, false);
    13021207
    1303 //    float diff = sqrtf(PS_SQR(PS_MAX(fwhm1, fwhm2)) - PS_SQR(PS_MIN(fwhm1, fwhm2))); // Difference
     1208    // float diff = sqrtf(PS_SQR(PS_MAX(fwhm1, fwhm2)) - PS_SQR(PS_MIN(fwhm1, fwhm2))); // Difference
    13041209    float scale = PS_MAX(fwhm1, fwhm2) / scaleRef;      // Scaling factor
    13051210
Note: See TracChangeset for help on using the changeset viewer.