- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psModules/src/imcombine/pmSubtractionParams.c
r21363 r27838 8 8 #include <pslib.h> 9 9 10 #include "pmErrorCodes.h" 10 11 #include "pmSubtractionStamps.h" 11 12 #include "pmSubtraction.h" … … 71 72 double *sumII, // Sum of I(x)^2/sigma(x)^2 72 73 double *sumIC, // Sum of I(x)conv(x)/sigma(x)^2 73 const pmSubtractionStamp *stamp, // Stamp with variance74 const pmSubtractionStamp *stamp, // Stamp 74 75 const psKernel *target, // Target stamp 75 76 int kernelIndex, // Index for kernel component … … 78 79 ) 79 80 { 80 psKernel * variance = stamp->variance; // Variance, sigma(x)^281 psKernel *weight = stamp->weight; // Weight image 81 82 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 82 83 83 84 for (int y = -footprint; y <= footprint; y++) { 84 85 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 85 psF32 *wt = & variance->kernel[y][-footprint]; // Dereference variance86 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 86 87 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 87 88 for (int x = -footprint; x <= footprint; x++, in++, wt++, conv++) { 88 double temp = *in /*wt; // Temporary product89 double temp = *in * *wt; // Temporary product 89 90 *sumI += temp; 90 91 *sumII += *in * temp; … … 98 99 static void accumulateConvolutions(double *sumC, // Sum of conv(x)/sigma(x)^2 99 100 double *sumCC, // Sum of conv(x)^2/sigma(x)^2 100 const pmSubtractionStamp *stamp, // Stamp with input and variance101 const pmSubtractionStamp *stamp, // Stamp with input and weight 101 102 int kernelIndex, // Index for kernel component 102 103 int footprint, // Size of region of interest … … 104 105 ) 105 106 { 106 psKernel * variance = stamp->variance; // Variance, sigma(x)^2107 psKernel *weight = stamp->weight; // Weight image 107 108 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 108 109 109 110 for (int y = -footprint; y <= footprint; y++) { 110 psF32 *wt = & variance->kernel[y][-footprint]; // Dereference variance111 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 111 112 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 112 113 for (int x = -footprint; x <= footprint; x++, wt++, conv++) { 113 double convNoise = *conv /*wt; // Temporary product114 double convNoise = *conv * *wt; // Temporary product 114 115 *sumC += convNoise; 115 116 *sumCC += *conv * convNoise; … … 120 121 121 122 static double accumulateChi2(const psKernel *target, // Target stamp 122 pmSubtractionStamp *stamp, // Stamp with variance123 pmSubtractionStamp *stamp, // Stamp with weight 123 124 int kernelIndex, // Index for kernel component 124 125 double coeff, // Coefficient of convolution … … 129 130 { 130 131 double chi2 = 0.0; 131 psKernel * variance = stamp->variance; // Variance, sigma(x)^2132 psKernel *weight = stamp->weight; // Weight image 132 133 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 133 134 134 135 for (int y = -footprint; y <= footprint; y++) { 135 136 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 136 psF32 *wt = & variance->kernel[y][-footprint]; // Dereference variance137 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 137 138 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 138 139 for (int x = -footprint; x <= footprint; x++, in++, wt++, conv++) { 139 chi2 += PS_SQR(*in - bg - coeff * *conv) /*wt;140 chi2 += PS_SQR(*in - bg - coeff * *conv) * *wt; 140 141 } 141 142 } … … 146 147 // Return the initial value of chi^2 147 148 static double initialChi2(const psKernel *target, // Target stamp 148 const pmSubtractionStamp *stamp, // Stamp with variance149 const pmSubtractionStamp *stamp, // Stamp 149 150 int footprint, // Size of convolution 150 151 pmSubtractionMode mode // Mode of subtraction 151 152 ) 152 153 { 153 psKernel * variance = stamp->variance; // Variance map154 psKernel *weight = stamp->weight; // Weight image 154 155 psKernel *source; // Source stamp 155 156 switch (mode) { … … 167 168 for (int y = -footprint; y <= footprint; y++) { 168 169 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 169 psF32 *wt = & variance->kernel[y][-footprint]; // Dereference variance170 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 170 171 psF32 *ref = &source->kernel[y][-footprint]; // Derference reference 171 172 for (int x = -footprint; x <= footprint; x++, in++, wt++, ref++) { 172 173 float diff = *in - *ref; // Temporary value 173 chi2 += PS_SQR(diff) /*wt;174 chi2 += PS_SQR(diff) * *wt; 174 175 } 175 176 } … … 180 181 // Subtract a convolution from the input 181 182 static void subtractConvolution(psKernel *target, // Target stamp 182 const pmSubtractionStamp *stamp, // Stamp with variance183 const pmSubtractionStamp *stamp, // Stamp 183 184 int kernelIndex, // Index for kernel component 184 185 float coeff, // Coefficient of subtraction … … 204 205 int spatialOrder, const psVector *fwhms, int maxOrder, 205 206 const pmSubtractionStampList *stamps, int footprint, 206 float tolerance, float penalty, pmSubtractionMode mode) 207 float tolerance, float penalty, psRegion bounds, 208 pmSubtractionMode mode) 207 209 { 208 210 if (type != PM_SUBTRACTION_KERNEL_ISIS && type != PM_SUBTRACTION_KERNEL_GUNK) { … … 232 234 psVectorInit(orders, maxOrder); 233 235 pmSubtractionKernels *kernels = p_pmSubtractionKernelsRawISIS(size, spatialOrder, fwhms, orders, 234 penalty, mode); // Kernels236 penalty, bounds, mode); // Kernels 235 237 psFree(orders); 236 238 psFree(kernels->description); … … 280 282 } 281 283 if (!pmSubtractionConvolveStamp(stamp, kernels, footprint)) { 282 psError( PS_ERR_UNKNOWN, false, "Unable to convolve stamp %d.", i);284 psError(psErrorCodeLast(), false, "Unable to convolve stamp %d.", i); 283 285 psFree(targets); 284 286 psFree(kernels); … … 288 290 289 291 // This sum is invariant to the kernel 290 psKernel * variance = stamp->variance; // Variance map for stamp292 psKernel *weight = stamp->weight; // Weight image 291 293 for (int v = -footprint; v <= footprint; v++) { 292 psF32 *wt = & variance->kernel[v][-footprint]; // Dereference variance map294 psF32 *wt = &weight->kernel[v][-footprint]; // Dereference weight 293 295 for (int u = -footprint; u <= footprint; u++, wt++) { 294 sum1 += 1.0 /*wt;296 sum1 += 1.0 * *wt; 295 297 } 296 298 } 297 299 if (!isfinite(sum1)) { 298 psError(P S_ERR_BAD_PARAMETER_VALUE, true,300 psError(PM_ERR_DATA, true, 299 301 "Sum of 1/sigma^2 is non-finite for stamp %d (%d,%d)\n", 300 302 i, (int)stamp->x, (int)stamp->y); … … 368 370 369 371 if (bestIndex == -1) { 370 psError(P S_ERR_UNKNOWN, false, "Unable to find best kernel component in round %d.", iter);372 psError(PM_ERR_DATA, true, "Unable to find best kernel component in round %d.", iter); 371 373 psFree(targets); 372 374 psFree(sumC); … … 407 409 408 410 if (cutIndex < 0) { 409 psError(P S_ERR_BAD_PARAMETER_VALUE, true, "Unable to converge to tolerance %g\n", tolerance);411 psError(PM_ERR_DATA, true, "Unable to converge to tolerance %g\n", tolerance); 410 412 psFree(ranking); 411 413 psFree(kernels); … … 482 484 // Maintain photometric scaling 483 485 if (type == PM_SUBTRACTION_KERNEL_ISIS) { 484 psKernel *subtract = kernels->preCalc->data[0]; // Kernel to subtract from the rest 486 487 // XXX in r26035, this code was just wrong. we had: 488 489 // psKernel *subtract = kernels->preCalc->data[0] 490 491 // but, kernels->preCalc was an array of psArray, not an array of kernels. It is now 492 // an array of pmSubtractionKernelPreCalc. 493 494 pmSubtractionKernelPreCalc *subtract = kernels->preCalc->data[0]; // Kernel to subtract from the rest 495 485 496 for (int i = 1; i < newSize; i++) { 486 497 if (kernels->u->data.S32[i] % 2 == 0 && kernels->v->data.S32[i] % 2 == 0) { 487 p sKernel *kernel= kernels->preCalc->data[i]; // Kernel of interest488 psBinaryOp( kernel->image, kernel->image, "-", subtract->image);498 pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[i]; // Kernel of interest 499 psBinaryOp(preCalc->kernel->image, preCalc->kernel->image, "-", subtract->kernel->image); 489 500 } 490 501 } … … 495 506 for (int i = 0; i < newSize; i++) { 496 507 if (kernels->u->data.S32[i] % 2 == 0 && kernels->v->data.S32[i] % 2 == 0) { 497 p sKernel *kernel= kernels->preCalc->data[i]; // Kernel of interest498 kernel->kernel[0][0] -= 1.0;508 pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[i]; // Kernel of interest 509 preCalc->kernel->kernel[0][0] -= 1.0; 499 510 } 500 511 }
Note:
See TracChangeset
for help on using the changeset viewer.
