Changeset 18239
- Timestamp:
- Jun 20, 2008, 10:00:01 AM (18 years ago)
- Location:
- branches/pap_branch_080617/psModules/src/imcombine
- Files:
-
- 4 edited
-
pmSubtractionEquation.c (modified) (5 diffs)
-
pmSubtractionKernels.c (modified) (13 diffs)
-
pmSubtractionKernels.h (modified) (1 diff)
-
pmSubtractionMatch.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionEquation.c
r17825 r18239 382 382 } 383 383 384 385 // Add in penalty term to least-squares vector 386 static bool calculatePenalty(int numPixels, // Number of pixels; for normalisation 387 psVector *vector, // Vector to which to add in penalty term 388 const pmSubtractionKernels *kernels // Kernel parameters 389 ) 390 { 391 if (kernels->penalty == 0.0) { 392 return true; 393 } 394 395 float penalty = numPixels * kernels->penalty; // Penalty value 396 psVector *penalties = kernels->penalties; // Penalties for each kernel component 397 int spatialOrder = kernels->spatialOrder; // Order of spatial variations 398 int numKernels = kernels->num; // Number of kernel components 399 for (int i = 0; i < numKernels; i++) { 400 for (int yOrder = 0, index = i; yOrder <= spatialOrder; yOrder++) { 401 for (int xOrder = 0; xOrder <= spatialOrder - yOrder; xOrder++, index += numKernels) { 402 vector->data.F64[index] -= penalty * penalties->data.F32[i]; 403 } 404 } 405 } 406 407 return true; 408 } 409 384 410 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 385 411 // Semi-public functions 386 // XXX EAM these cannot be inline :: talk to Josh 412 // XXX We might like to define these functions as "extern inline" but gcc currently doesn't handle this in c99 413 // mode. See http://gcc.gnu.org/ml/gcc/2006-11/msg00006.html 387 414 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 388 415 … … 675 702 psVectorInit(sumVector, 0.0); 676 703 psImageInit(sumMatrix, 0.0); 704 int numStamps = 0; // Number of good stamps 677 705 for (int i = 0; i < stamps->num; i++) { 678 706 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest … … 680 708 (void)psBinaryOp(sumMatrix, sumMatrix, "+", stamp->matrix1); 681 709 (void)psBinaryOp(sumVector, sumVector, "+", stamp->vector1); 682 } 683 } 710 numStamps++; 711 } 712 } 713 calculatePenalty(numStamps * PS_SQR(2 * stamps->footprint + 1), sumVector, kernels); 684 714 685 715 psVector *permutation = NULL; // Permutation vector, required for LU decomposition … … 716 746 psVectorInit(sumVector2, 0.0); 717 747 748 int numStamps = 0; // Number of good stamps 718 749 for (int i = 0; i < stamps->num; i++) { 719 750 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest … … 724 755 (void)psBinaryOp(sumVector1, sumVector1, "+", stamp->vector1); 725 756 (void)psBinaryOp(sumVector2, sumVector2, "+", stamp->vector2); 726 } 727 } 757 numStamps++; 758 } 759 } 760 calculatePenalty(numStamps * PS_SQR(2 * stamps->footprint + 1), sumVector1, kernels); 761 calculatePenalty(numStamps * PS_SQR(2 * stamps->footprint + 1), sumVector2, kernels); 728 762 729 763 #if 0 -
branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionKernels.c
r18146 r18239 24 24 psFree(kernels->vStop); 25 25 psFree(kernels->preCalc); 26 psFree(kernels->penalties); 26 27 psFree(kernels->solution1); 27 28 psFree(kernels->solution2); … … 60 61 kernels->v = psVectorRealloc(kernels->v, start + numNew); 61 62 kernels->preCalc = psArrayRealloc(kernels->preCalc, start + numNew); 63 kernels->penalties = psVectorRealloc(kernels->penalties, start + numNew); 62 64 kernels->inner = start; 63 65 … … 74 76 kernels->v->data.S32[index] = v; 75 77 kernels->preCalc->data[index] = NULL; 78 kernels->penalties->data.F32[index] = PS_SQR(u) + PS_SQR(v); 76 79 77 80 psTrace("psModules.imcombine", 7, "Kernel %d: %d %d\n", index, u, v); … … 122 125 psKernel *preCalc = psKernelAlloc(-size, size, -size, size); 123 126 double sum = 0.0; // Normalisation 127 double moment = 0.0; // Moment, for penalty 124 128 for (int v = -size; v <= size; v++) { 125 129 for (int u = -size; u <= size; u++) { 126 130 sum += preCalc->kernel[v][u] = norm * power(u, uOrder) * power(v, vOrder) * 127 131 expf(-0.5 * (PS_SQR(u) + PS_SQR(v)) / PS_SQR(sigma)); 132 moment += preCalc->kernel[v][u] * sqrtf(PS_SQR(u) + PS_SQR(v)); 128 133 } 129 134 } … … 146 151 } 147 152 kernels->preCalc->data[index] = preCalc; 153 kernels->penalties->data.F32[index] = moment; 148 154 149 155 psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d\n", index, … … 173 179 kernels->widths = psVectorAlloc(numBasisFunctions, PS_TYPE_F32); 174 180 kernels->preCalc = psArrayAlloc(numBasisFunctions); 181 kernels->penalty = 0.0; 182 kernels->penalties = psVectorAlloc(numBasisFunctions, PS_TYPE_F32); 175 183 kernels->uStop = NULL; 176 184 kernels->vStop = NULL; … … 324 332 psFree(widths); 325 333 334 psWarning("Kernel penalty for dual-convolution is not configured for SPAM kernels."); 335 psVectorInit(kernels->penalties, 0.0); 336 326 337 return kernels; 327 338 } … … 413 424 psFree(start); 414 425 psFree(stop); 426 427 psWarning("Kernel penalty for dual-convolution is not configured for FRIES kernels."); 428 psVectorInit(kernels->penalties, 0.0); 415 429 416 430 return kernels; … … 520 534 psVector *vCoords = data->data[1] = psVectorAllocEmpty(RINGS_BUFFER, PS_TYPE_S32); // v coords 521 535 psVector *poly = data->data[2] = psVectorAllocEmpty(RINGS_BUFFER, PS_TYPE_F32); // Polynomial 536 double moment = 0.0; // Moment, for penalty 522 537 523 538 if (i == 0) { … … 527 542 uCoords->n = vCoords->n = poly->n = 1; 528 543 radiusLast = 0; 544 moment = 0.0; 529 545 } else { 530 546 int j = 0; // Index for data … … 546 562 poly->data.F32[j] = polyVal; 547 563 norm += polyVal; 564 moment += polyVal * sqrtf(PS_SQR(u) + PS_SQR(v)); 548 565 549 566 psVectorExtend(uCoords, RINGS_BUFFER, 1); … … 571 588 psBinaryOp(poly, poly, "*", psScalarAlloc(1.0 / norm, PS_TYPE_F32)); 572 589 } 590 moment /= norm; 573 591 } 574 592 … … 578 596 kernels->u->data.S32[index] = uOrder; 579 597 kernels->v->data.S32[index] = vOrder; 598 kernels->penalties->data.F32[index] = moment; 580 599 581 600 psTrace("psModules.imcombine", 7, "Kernel %d: %d %d %d\n", index, -
branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionKernels.h
r18146 r18239 33 33 psVector *uStop, *vStop; ///< Width of kernel element (SPAM,FRIES only) 34 34 psArray *preCalc; ///< Array of images containing pre-calculated kernel (for ISIS) 35 float penalty; ///< Penalty value 36 psVector *penalties; ///< Penalty for each kernel component 35 37 int size; ///< The half-size of the kernel 36 38 int inner; ///< The size of an inner region -
branches/pap_branch_080617/psModules/src/imcombine/pmSubtractionMatch.c
r17783 r18239 430 430 // Generate image with convolution kernels 431 431 int fullSize = 2 * size + 1 + 1; // Full size of kernel 432 psImage *convKernels = psImageAlloc(5 * fullSize - 1, 5 * fullSize - 1, PS_TYPE_F32); 432 int imageSize = (2 * KERNEL_MOSAIC + 1) * fullSize; 433 psImage *convKernels = psImageAlloc((mode == PM_SUBTRACTION_MODE_DUAL ? 2 : 1) * 434 imageSize - 1 + 435 (mode == PM_SUBTRACTION_MODE_DUAL ? 4 : 0), 436 imageSize - 1, PS_TYPE_F32); 433 437 psImageInit(convKernels, NAN); 434 438 for (int j = -KERNEL_MOSAIC; j <= KERNEL_MOSAIC; j++) { … … 451 455 } 452 456 psFree(kernel); 457 458 if (mode == PM_SUBTRACTION_MODE_DUAL) { 459 kernel = pmSubtractionKernelImage(kernels, (float)i / (float)KERNEL_MOSAIC, 460 (float)j / (float)KERNEL_MOSAIC, 461 true); // Image of the kernel 462 if (!kernel) { 463 psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image."); 464 psFree(convKernels); 465 goto MATCH_ERROR; 466 } 467 468 if (psImageOverlaySection(convKernels, kernel, 469 (2 * KERNEL_MOSAIC + 1 + i + KERNEL_MOSAIC) * fullSize + 470 4, 471 (j + KERNEL_MOSAIC) * fullSize, "=") == 0) { 472 psError(PS_ERR_UNKNOWN, false, "Unable to overlay kernel image."); 473 psFree(kernel); 474 psFree(convKernels); 475 goto MATCH_ERROR; 476 } 477 psFree(kernel); 478 } 479 453 480 } 454 481 }
Note:
See TracChangeset
for help on using the changeset viewer.
