Changeset 26332
- Timestamp:
- Dec 3, 2009, 12:20:59 PM (16 years ago)
- Location:
- branches/eam_branches/20091201/psModules/src/imcombine
- Files:
-
- 5 edited
-
pmSubtraction.c (modified) (1 diff)
-
pmSubtractionEquation.c (modified) (21 diffs)
-
pmSubtractionEquation.h (modified) (2 diffs)
-
pmSubtractionMatch.c (modified) (4 diffs)
-
pmSubtractionVisual.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtraction.c
r26047 r26332 462 462 { 463 463 psArray *preCalc = kernels->preCalc->data[index]; // Precalculated data 464 #if 1464 #if 0 465 465 // Convolving using separable convolution 466 466 psVector *xKernel = preCalc->data[0]; // Kernel in x -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c
r26330 r26332 26 26 27 27 // 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...) 28 29 static bool calculateMatrixVector(psImage *matrix, // Least-squares matrix, updated 29 30 psVector *vector, // Least-squares vector, updated … … 36 37 const psImage *polyValues, // Spatial polynomial values 37 38 int footprint, // (Half-)Size of stamp 38 const bool normOnly39 const pmSubtractionEquationCalculationMode mode 39 40 ) 40 41 { … … 54 55 55 56 // Evaluate polynomial-polynomial terms 56 // XXX we can skip this for normOnly57 // XXX we can skip this if we are not calculating kernel coeffs 57 58 for (int iyOrder = 0, iIndex = 0; iyOrder <= spatialOrder; iyOrder++) { 58 59 for (int ixOrder = 0; ixOrder <= spatialOrder - iyOrder; ixOrder++, iIndex++) { … … 68 69 } 69 70 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) { 91 96 cc *= weight->kernel[y][x]; 92 #endif93 #ifdef USE_WINDOW94 if (window) {95 cc *= window->kernel[y][x];96 }97 #endif98 sumCC += cc;99 97 } 98 if (window) { 99 cc *= window->kernel[y][x]; 100 } 101 sumCC += cc; 100 102 } 101 102 // Spatial variation 103 } 104 105 // Spatial variation of kernel coeffs 106 if (mode | PM_SUBTRACTION_EQUATION_KERNELS) { 103 107 for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) { 104 108 for (int jTerm = 0, jIndex = j; jTerm < numPoly; jTerm++, jIndex += numKernels) { … … 109 113 } 110 114 } 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) { 124 129 float wtVal = weight->kernel[y][x]; 125 130 ic *= wtVal; 126 131 rc *= wtVal; 127 132 c *= wtVal; 128 #endif129 #ifdef USE_WINDOW130 if (window) {131 float winVal = window->kernel[y][x];132 ic *= winVal;133 rc *= winVal;134 c *= winVal;135 }136 #endif137 sumIC += ic;138 sumRC += rc;139 sumC += c;140 133 } 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; 141 143 } 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)) { 146 150 matrix->data.F64[iIndex][normIndex] = normTerm; 147 151 matrix->data.F64[normIndex][iIndex] = normTerm; 152 } 153 if ((mode | PM_SUBTRACTION_EQUATION_BG) && (mode | PM_SUBTRACTION_EQUATION_KERNELS)) { 148 154 matrix->data.F64[iIndex][bgIndex] = bgTerm; 149 155 matrix->data.F64[bgIndex][iIndex] = bgTerm; 156 } 157 if (mode | PM_SUBTRACTION_EQUATION_KERNELS) { 150 158 vector->data.F64[iIndex] = sumIC * poly[iTerm]; 151 159 } 152 160 } 153 161 } 154 155 // XXX need to disable normalization calculation if !normOnly156 162 157 163 double sumRR = 0.0; // Sum of the reference product … … 167 173 double rr = PS_SQR(ref); 168 174 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 } 178 183 if (window) { 179 184 float winVal = window->kernel[y][x]; … … 184 189 one *= winVal; 185 190 } 186 #endif187 191 sumRR += rr; 188 192 sumIR += ir; … … 192 196 } 193 197 } 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 } 200 210 return true; 201 211 } … … 267 277 double bb = iConv2->kernel[y][x] * jConv2->kernel[y][x]; 268 278 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 } 275 285 sumAA += aa; 276 286 sumBB += bb; … … 299 309 for (int x = - footprint; x <= footprint; x++) { 300 310 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 } 304 314 sumAB += ab; 305 315 } … … 336 346 double i1i2 = i1 * i2; 337 347 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 } 350 359 sumAI2 += ai2; 351 360 sumBI2 += bi2; … … 392 401 double i1i2 = i1 * i2; 393 402 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 } 403 411 sumI1 += i1; 404 412 sumI1I1 += i1i1; … … 588 596 const pmSubtractionKernels *kernels = job->args->data[1]; // Kernels 589 597 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); 592 601 } 593 602 594 603 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, 595 int index, bool normOnly)604 int index, const pmSubtractionEquationCalculationMode mode) 596 605 { 597 606 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 662 671 663 672 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 664 684 switch (kernels->mode) { 665 685 case PM_SUBTRACTION_MODE_1: 666 686 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); 669 689 break; 670 690 case PM_SUBTRACTION_MODE_2: 671 691 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); 674 694 break; 675 695 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"); 677 697 if (new) { 678 698 stamp->matrix2 = psImageAlloc(numKernels * numSpatial, numKernels * numSpatial, PS_TYPE_F64); … … 686 706 #endif 687 707 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, 689 709 stamp->convolutions1, stamp->convolutions2, kernels, polyValues, 690 710 footprint); … … 758 778 } 759 779 760 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, const bool normOnly)780 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, const pmSubtractionEquationCalculationMode mode) 761 781 { 762 782 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 778 798 psArrayAdd(job->args, 1, (pmSubtractionKernels*)kernels); // Casting away const to put on array 779 799 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); 781 801 if (!psThreadJobAddPending(job)) { 782 802 psFree(job); … … 785 805 psFree(job); 786 806 } else { 787 pmSubtractionCalculateEquationStamp(stamps, kernels, i, normOnly);807 pmSubtractionCalculateEquationStamp(stamps, kernels, i, mode); 788 808 } 789 809 } … … 803 823 } 804 824 805 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, const pmSubtractionStampList *stamps) 825 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, 826 const pmSubtractionStampList *stamps, 827 const pmSubtractionEquationCalculationMode mode) 806 828 { 807 829 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, false); … … 941 963 return NULL; 942 964 } 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); 944 998 945 999 #ifdef TESTING … … 952 1006 #endif 953 1007 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 }961 1008 } else { 962 1009 // Dual convolution solution -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.h
r26330 r26332 4 4 #include "pmSubtractionStamps.h" 5 5 #include "pmSubtractionKernels.h" 6 7 typedef 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; 6 14 7 15 /// Execute a thread job to calculate the least-squares equation for a stamp … … 13 21 const pmSubtractionKernels *kernels, ///< Kernel parameters 14 22 int index, ///< Index of stamp 15 const bool normOnly16 );23 const pmSubtractionEquationCalculationMode mode 24 ); 17 25 18 26 /// Calculate the least-squares equation to match the image quality 19 27 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps 20 28 const pmSubtractionKernels *kernels, ///< Kernel parameters 21 const bool normOnly22 );29 const pmSubtractionEquationCalculationMode mode 30 ); 23 31 24 32 /// Solve the least-squares equation to match the image quality 25 33 bool pmSubtractionSolveEquation(pmSubtractionKernels *kernels, ///< Kernel parameters 26 const pmSubtractionStampList *stamps ///< Stamps 34 const pmSubtractionStampList *stamps, ///< Stamps 35 const pmSubtractionEquationCalculationMode mode 27 36 ); 28 37 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.c
r26330 r26332 561 561 562 562 // 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)) { 565 566 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 566 567 goto MATCH_ERROR; 567 568 } 568 569 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 570 578 # 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)) { 573 582 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 574 583 goto MATCH_ERROR; 575 584 } 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"); 576 593 # 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");588 594 589 595 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations … … 609 615 // if we hit the max number of iterations and we have rejected stamps, re-solve 610 616 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)) { 613 621 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 614 622 goto MATCH_ERROR; 615 623 } 624 memCheck(" solve equation"); 625 616 626 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 617 627 if (!deviations) { … … 918 928 assert(kernels); 919 929 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)) { 922 933 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 923 934 return false; 924 935 } 925 936 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)) { 928 940 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 929 941 return false; 930 942 } 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 931 957 932 958 psTrace("psModules.imcombine", 3, "Calculate %s deviations...\n", description); … … 949 975 // Allow re-fit with reduced stamps set 950 976 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)) { 952 979 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 953 980 return false; 954 981 } 955 982 psTrace("psModules.imcombine", 3, "Recalculate %s deviations...\n", description); 983 956 984 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 957 985 if (!deviations) { -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionVisual.c
r26318 r26332 263 263 static psImage *targetImage = NULL; 264 264 static psImage *residualImage = NULL; 265 static psImage *fresidualImage = NULL; 265 266 static psImage *differenceImage = NULL; 266 267 static psImage *convolutionImage = NULL; … … 289 290 targetImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 290 291 residualImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 292 fresidualImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 291 293 differenceImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); 292 294 convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32); … … 295 297 psImageInit (targetImage, 0.0); 296 298 psImageInit (residualImage, 0.0); 299 psImageInit (fresidualImage, 0.0); 297 300 psImageInit (differenceImage, 0.0); 298 301 psImageInit (convolutionImage, 0.0); … … 343 346 for (int x = -footprint; x <= footprint; x++) { 344 347 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]; 345 355 } 346 356 } … … 358 368 pmVisualScaleImage(kapa1, convolutionImage, "Convolution Stamps", 2, true); 359 369 370 // pmVisualScaleImage(kapa2, fresidualImage, "Frac Residual Stamps", 2, true); 371 pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true); 360 372 pmVisualScaleImage(kapa2, differenceImage, "Difference Stamps", 0, true); 361 pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true);362 373 pmVisualAskUser(NULL); 363 374 … … 367 378 psFree(differenceImage); 368 379 psFree(residualImage); 380 psFree(fresidualImage); 369 381 370 382 targetImage = NULL; … … 373 385 differenceImage = NULL; 374 386 residualImage = NULL; 387 fresidualImage = NULL; 375 388 376 389 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
