Changeset 26330
- Timestamp:
- Dec 3, 2009, 2:30:10 AM (16 years ago)
- Location:
- branches/eam_branches/20091201/psModules/src/imcombine
- Files:
-
- 4 edited
-
pmSubtractionEquation.c (modified) (10 diffs)
-
pmSubtractionEquation.h (modified) (1 diff)
-
pmSubtractionMatch.c (modified) (2 diffs)
-
pmSubtractionThreads.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.c
r26318 r26330 35 35 const pmSubtractionKernels *kernels, // Kernels 36 36 const psImage *polyValues, // Spatial polynomial values 37 int footprint // (Half-)Size of stamp 37 int footprint, // (Half-)Size of stamp 38 const bool normOnly 38 39 ) 39 40 { … … 53 54 54 55 // Evaluate polynomial-polynomial terms 56 // XXX we can skip this for normOnly 55 57 for (int iyOrder = 0, iIndex = 0; iyOrder <= spatialOrder; iyOrder++) { 56 58 for (int ixOrder = 0; ixOrder <= spatialOrder - iyOrder; ixOrder++, iIndex++) { … … 67 69 68 70 69 for (int i = 0; i < numKernels; i++) { 70 psKernel *iConv = convolutions->data[i]; // Convolution for index i 71 for (int j = i; j < numKernels; j++) { 72 psKernel *jConv = convolutions->data[j]; // Convolution for index j 73 74 double sumCC = 0.0; // Sum of convolution products 75 for (int y = - footprint; y <= footprint; y++) { 76 for (int x = - footprint; x <= footprint; x++) { 77 double cc = iConv->kernel[y][x] * jConv->kernel[y][x]; 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]; 78 90 #ifdef USE_WEIGHT 79 cc *= weight->kernel[y][x]; 91 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; 99 } 100 } 101 102 // Spatial variation 103 for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) { 104 for (int jTerm = 0, jIndex = j; jTerm < numPoly; jTerm++, jIndex += numKernels) { 105 double value = sumCC * poly2[iTerm][jTerm]; 106 matrix->data.F64[iIndex][jIndex] = value; 107 matrix->data.F64[jIndex][iIndex] = value; 108 } 109 } 110 } 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 124 float wtVal = weight->kernel[y][x]; 125 ic *= wtVal; 126 rc *= wtVal; 127 c *= wtVal; 80 128 #endif 81 129 #ifdef USE_WINDOW 82 130 if (window) { 83 cc *= window->kernel[y][x]; 131 float winVal = window->kernel[y][x]; 132 ic *= winVal; 133 rc *= winVal; 134 c *= winVal; 84 135 } 85 136 #endif 86 sumCC += cc; 87 } 88 } 89 90 // Spatial variation 91 for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) { 92 for (int jTerm = 0, jIndex = j; jTerm < numPoly; jTerm++, jIndex += numKernels) { 93 double value = sumCC * poly2[iTerm][jTerm]; 94 matrix->data.F64[iIndex][jIndex] = value; 95 matrix->data.F64[jIndex][iIndex] = value; 96 } 97 } 98 } 99 100 double sumRC = 0.0; // Sum of the reference-convolution products 101 double sumIC = 0.0; // Sum of the input-convolution products 102 double sumC = 0.0; // Sum of the convolution 103 for (int y = - footprint; y <= footprint; y++) { 104 for (int x = - footprint; x <= footprint; x++) { 105 float conv = iConv->kernel[y][x]; 106 float in = input->kernel[y][x]; 107 float ref = reference->kernel[y][x]; 108 double ic = in * conv; 109 double rc = ref * conv; 110 double c = conv; 111 #ifdef USE_WEIGHT 112 float wtVal = weight->kernel[y][x]; 113 ic *= wtVal; 114 rc *= wtVal; 115 c *= wtVal; 116 #endif 117 #ifdef USE_WINDOW 118 if (window) { 119 float winVal = window->kernel[y][x]; 120 ic *= winVal; 121 rc *= winVal; 122 c *= winVal; 137 sumIC += ic; 138 sumRC += rc; 139 sumC += c; 123 140 } 124 #endif 125 sumIC += ic; 126 sumRC += rc; 127 sumC += c; 128 } 129 } 130 // Spatial variation 131 for (int iTerm = 0, iIndex = i; iTerm < numPoly; iTerm++, iIndex += numKernels) { 132 double normTerm = sumRC * poly[iTerm]; 133 double bgTerm = sumC * poly[iTerm]; 134 matrix->data.F64[iIndex][normIndex] = normTerm; 135 matrix->data.F64[normIndex][iIndex] = normTerm; 136 matrix->data.F64[iIndex][bgIndex] = bgTerm; 137 matrix->data.F64[bgIndex][iIndex] = bgTerm; 138 vector->data.F64[iIndex] = sumIC * poly[iTerm]; 139 } 140 } 141 } 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]; 146 matrix->data.F64[iIndex][normIndex] = normTerm; 147 matrix->data.F64[normIndex][iIndex] = normTerm; 148 matrix->data.F64[iIndex][bgIndex] = bgTerm; 149 matrix->data.F64[bgIndex][iIndex] = bgTerm; 150 vector->data.F64[iIndex] = sumIC * poly[iTerm]; 151 } 152 } 153 } 154 155 // XXX need to disable normalization calculation if !normOnly 141 156 142 157 double sumRR = 0.0; // Sum of the reference product … … 574 589 int index = PS_SCALAR_VALUE(job->args->data[2], S32); // Stamp index 575 590 576 return pmSubtractionCalculateEquationStamp(stamps, kernels, index );591 return pmSubtractionCalculateEquationStamp(stamps, kernels, index, normOnly); 577 592 } 578 593 579 594 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, 580 int index )595 int index, bool normOnly) 581 596 { 582 597 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 591 606 int numBackground = PM_SUBTRACTION_POLYTERMS(kernels->bgOrder); // Number of background terms 592 607 608 // numKernels is the number of unique kernel images (one for each Gaussian modified by a specific polynomial). 609 // = \sum_i^N_Gaussians [(order + 1) * (order + 2) / 2], eg for 1 Gauss and 1st order, numKernels = 3 610 593 611 // Total number of parameters to solve for: coefficient of each kernel basis function, multipled by the 594 612 // number of coefficients for the spatial polynomial, normalisation and a constant background offset. … … 598 616 psAssert(stamp->status == PM_SUBTRACTION_STAMP_CALCULATE, "We only operate on stamps with this state."); 599 617 600 // Generate convolutions 618 // Generate convolutions: these are generated once and saved 601 619 if (!pmSubtractionConvolveStamp(stamp, kernels, footprint)) { 602 620 psError(PS_ERR_UNKNOWN, false, "Unable to convolve stamp %d.", index); … … 648 666 status = calculateMatrixVector(stamp->matrix1, stamp->vector1, stamp->image2, stamp->image1, 649 667 stamp->weight, stamps->window, stamp->convolutions1, kernels, 650 polyValues, footprint );668 polyValues, footprint, normOnly); 651 669 break; 652 670 case PM_SUBTRACTION_MODE_2: 653 671 status = calculateMatrixVector(stamp->matrix1, stamp->vector1, stamp->image1, stamp->image2, 654 672 stamp->weight, stamps->window, stamp->convolutions2, kernels, 655 polyValues, footprint );673 polyValues, footprint, normOnly); 656 674 break; 657 675 case PM_SUBTRACTION_MODE_DUAL: 676 psAbort ("dual is disabled: need to add window and normOnly"); 658 677 if (new) { 659 678 stamp->matrix2 = psImageAlloc(numKernels * numSpatial, numKernels * numSpatial, PS_TYPE_F64); … … 739 758 } 740 759 741 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels )760 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, const pmSubtractionKernels *kernels, const bool normOnly) 742 761 { 743 762 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); … … 759 778 psArrayAdd(job->args, 1, (pmSubtractionKernels*)kernels); // Casting away const to put on array 760 779 PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32); 780 PS_ARRAY_ADD_SCALAR(job->args, normOnly, PS_TYPE_BOOL); 761 781 if (!psThreadJobAddPending(job)) { 762 782 psFree(job); … … 765 785 psFree(job); 766 786 } else { 767 pmSubtractionCalculateEquationStamp(stamps, kernels, i );787 pmSubtractionCalculateEquationStamp(stamps, kernels, i, normOnly); 768 788 } 769 789 } -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionEquation.h
r19299 r26330 12 12 bool pmSubtractionCalculateEquationStamp(pmSubtractionStampList *stamps, ///< Stamps 13 13 const pmSubtractionKernels *kernels, ///< Kernel parameters 14 int index ///< Index of stamp 14 int index, ///< Index of stamp 15 const bool normOnly 15 16 ); 16 17 17 18 /// Calculate the least-squares equation to match the image quality 18 19 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps 19 const pmSubtractionKernels *kernels ///< Kernel parameters 20 const pmSubtractionKernels *kernels, ///< Kernel parameters 21 const bool normOnly 20 22 ); 21 23 -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionMatch.c
r26318 r26330 560 560 } 561 561 562 // XXX step 1: calculate normalization 563 psTrace("psModules.imcombine", 3, "Calculating equation...\n"); 564 if (!pmSubtractionCalculateEquation(stamps, kernels, true)) { 565 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 566 goto MATCH_ERROR; 567 } 568 569 // XXX step 2: calculate only other parameters 570 # if (0) 562 571 psTrace("psModules.imcombine", 3, "Calculating equation...\n"); 563 572 if (!pmSubtractionCalculateEquation(stamps, kernels)) { … … 565 574 goto MATCH_ERROR; 566 575 } 576 # endif 567 577 568 578 memCheck(" calculate equation"); -
branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionThreads.c
r21363 r26330 69 69 70 70 { 71 psThreadTask *task = psThreadTaskAlloc("PSMODULES_SUBTRACTION_CALCULATE_EQUATION", 3);71 psThreadTask *task = psThreadTaskAlloc("PSMODULES_SUBTRACTION_CALCULATE_EQUATION", 4); 72 72 task->function = &pmSubtractionCalculateEquationThread; 73 73 psThreadTaskAdd(task);
Note:
See TracChangeset
for help on using the changeset viewer.
