Changeset 14738 for trunk/psModules/src/imcombine/pmSubtractionParams.c
- Timestamp:
- Sep 4, 2007, 1:56:07 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionParams.c
r14735 r14738 221 221 } 222 222 223 // Generate the convolutions 224 for (int i = 0; i < numStamps; i++) { 225 pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest 226 if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED || stamp->status == PM_SUBTRACTION_STAMP_NONE) { 227 continue; 228 } 229 if (!stamp->convolutions) { 230 stamp->convolutions = psArrayAlloc(numKernels); 231 } 232 233 for (int j = 0; j < numKernels; j++) { 234 psKernel *kernel = kernels->preCalc->data[j]; // Precalculated kernel 235 stamp->convolutions->data[j] = p_pmSubtractionConvolveStampPrecalc(stamp->reference, kernel); 236 } 237 } 238 239 // Calculate sums invariant with the input image 223 // Generate the convolutions, accumulate sums, and measure initial chi^2 240 224 double sum1 = 0.0; // sum of 1/sigma(x,y)^2 241 for (int i = 0; i < numStamps; i++) {242 pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest243 if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED || stamp->status == PM_SUBTRACTION_STAMP_NONE) {244 continue;245 }246 psKernel *weight = stamp->weight; // Weight map for stamp247 248 for (int v = -footprint; v <= footprint; v++) {249 psF32 *wt = &weight->kernel[v][-footprint]; // Dereference weight map250 for (int u = -footprint; u <= footprint; u++, wt++) {251 sum1 += 1.0 / *wt;252 }253 }254 if (!isfinite(sum1)) {255 psError(PS_ERR_BAD_PARAMETER_VALUE, true,256 "Sum of 1/sigma^2 is non-finite for stamp %d (%d,%d)\n",257 i, (int)stamp->x, (int)stamp->y);258 psFree(kernels);259 return NULL;260 }261 }262 225 psVector *sumC = psVectorAlloc(numKernels, PS_TYPE_F64); // sum of R(x)*k(u)/sigma(x)^2 263 226 psVector *sumCC = psVectorAlloc(numKernels, PS_TYPE_F64); // sum of [R(x)*k(u)]^2/sigma(x)^2 264 227 psVectorInit(sumC, 0.0); 265 228 psVectorInit(sumCC, 0.0); 266 for (int i = 0; i < numKernels; i++) {267 for (int j = 0; j < numStamps; j++) {268 pmSubtractionStamp *stamp = stamps->data[j]; // Stamp of interest269 if (stamp->status == PM_SUBTRACTION_STAMP_REJECTED ||270 stamp->status == PM_SUBTRACTION_STAMP_NONE) {271 continue;272 }273 accumulateConvolutions(&sumC->data.F64[i], &sumCC->data.F64[i], stamp, i, footprint);274 }275 }276 277 // Initial chi^2278 229 double lastChi2 = 0.0; // Chi^2 from last iteration 279 230 int numPixels = 0; // Number of pixels contributing to chi^2 … … 283 234 continue; 284 235 } 236 if (!pmSubtractionConvolveStamp(stamp, kernels, footprint)) { 237 psError(PS_ERR_UNKNOWN, false, "Unable to convolve stamp %d.", i); 238 psFree(inputs); 239 psFree(kernels); 240 return NULL; 241 } 242 243 // This sum is invariant to the kernel 244 psKernel *weight = stamp->weight; // Weight map for stamp 245 for (int v = -footprint; v <= footprint; v++) { 246 psF32 *wt = &weight->kernel[v][-footprint]; // Dereference weight map 247 for (int u = -footprint; u <= footprint; u++, wt++) { 248 sum1 += 1.0 / *wt; 249 } 250 } 251 if (!isfinite(sum1)) { 252 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 253 "Sum of 1/sigma^2 is non-finite for stamp %d (%d,%d)\n", 254 i, (int)stamp->x, (int)stamp->y); 255 psFree(inputs); 256 psFree(kernels); 257 return NULL; 258 } 259 260 for (int j = 0; j < numKernels; j++) { 261 accumulateConvolutions(&sumC->data.F64[j], &sumCC->data.F64[j], stamp, j, footprint); 262 } 263 285 264 lastChi2 += initialChi2(inputs->data[i], stamp, footprint); 286 265 numPixels += PS_SQR(2 * footprint + 1); … … 395 374 psVector *widthsNew = psVectorAlloc(newSize, PS_TYPE_F32); 396 375 psArray *preCalcNew = psArrayAlloc(newSize); 376 psArray *convNew = psArrayAlloc(numStamps); 377 for (int i = 0; i < numStamps; i++) { 378 convNew->data[i] = psArrayAlloc(newSize); 379 } 397 380 398 381 for (int i = 0; i < numKernels; i++) { … … 403 386 widthsNew->data.F32[rank] = kernels->widths->data.F32[i]; 404 387 preCalcNew->data[rank] = psMemIncrRefCounter(kernels->preCalc->data[i]); 388 389 for (int j = 0; j < numStamps; j++) { 390 psArray *convolutions = convNew->data[j]; // Convolutions for this stamp 391 pmSubtractionStamp *stamp = stamps->data[j]; // Stamp of interest 392 convolutions->data[rank] = psMemIncrRefCounter(stamp->convolutions->data[i]); 393 } 405 394 } 406 395 } … … 415 404 kernels->num = newSize; 416 405 406 for (int i = 0; i < numStamps; i++) { 407 pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest 408 psFree(stamp->convolutions); 409 stamp->convolutions = convNew->data[i]; 410 } 411 417 412 psFree(ranking); 418 413
Note:
See TracChangeset
for help on using the changeset viewer.
