Changeset 26717
- Timestamp:
- Jan 28, 2010, 5:32:15 PM (16 years ago)
- Location:
- branches/pap/psModules/src/imcombine
- Files:
-
- 6 edited
-
pmSubtraction.c (modified) (4 diffs)
-
pmSubtractionEquation.c (modified) (15 diffs)
-
pmSubtractionKernels.c (modified) (4 diffs)
-
pmSubtractionKernels.h (modified) (6 diffs)
-
pmSubtractionStamps.c (modified) (1 diff)
-
pmSubtractionStamps.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/psModules/src/imcombine/pmSubtraction.c
r26667 r26717 188 188 if (normalise) { 189 189 // Put in the normalisation component 190 kernel->kernel[0][0] += (wantDual ? 1.0 : p_pmSubtractionSolutionNorm(kernels)); 190 // kernel->kernel[0][0] += (wantDual ? 1.0 : p_pmSubtractionSolutionNorm(kernels)); 191 double value = wantDual ? 1.0 : p_pmSubtractionSolutionNorm(kernels); 192 for (int v = -size; v <= size; v++) { 193 for (int u = -size; u <= size; u++) { 194 kernel->kernel[v][u] += value * kernels->norm->kernel[v][u]; 195 } 196 } 191 197 } 192 198 … … 754 760 case PM_SUBTRACTION_MODE_1: 755 761 stamp->convolutions1 = convolveStamp(stamp->convolutions1, stamp->image1, kernels, footprint); 762 stamp->normConv = p_pmSubtractionConvolveStampPrecalc(stamp->image1, kernels->norm); 756 763 break; 757 764 case PM_SUBTRACTION_MODE_2: 758 765 stamp->convolutions2 = convolveStamp(stamp->convolutions2, stamp->image2, kernels, footprint); 766 stamp->normConv = p_pmSubtractionConvolveStampPrecalc(stamp->image2, kernels->norm); 759 767 break; 760 768 case PM_SUBTRACTION_MODE_UNSURE: … … 762 770 stamp->convolutions1 = convolveStamp(stamp->convolutions1, stamp->image1, kernels, footprint); 763 771 stamp->convolutions2 = convolveStamp(stamp->convolutions2, stamp->image2, kernels, footprint); 772 stamp->normConv = p_pmSubtractionConvolveStampPrecalc(stamp->image1, kernels->norm); 764 773 break; 765 774 default: … … 908 917 psFree(stamp->vector); 909 918 stamp->vector = NULL; 919 920 psFree(stamp->normConv); 921 stamp->normConv = NULL; 910 922 } else { 911 923 numGood++; -
branches/pap/psModules/src/imcombine/pmSubtractionEquation.c
r26703 r26717 229 229 const psArray *convolutions1, // Convolutions of image 1 for each kernel 230 230 const psArray *convolutions2, // Convolutions of image 2 for each kernel 231 const psKernel *normConv, // Normalisation, convolved 231 232 const pmSubtractionKernels *kernels, // Kernels 232 233 const psImage *polyValues, // Spatial polynomial values … … 370 371 double sumB = 0.0; // Sum of B products (for matrix, background) 371 372 double sumI2 = 0.0; // Sum of I_2 (for vector, background) 373 374 double sumAN = 0.0; // Matrix: A*norm 375 double sumBN = 0.0; // Matrix: B*norm 376 372 377 for (int y = - footprint; y <= footprint; y++) { 373 378 for (int x = - footprint; x <= footprint; x++) { 374 379 double a = iConv1->kernel[y][x]; 375 380 double b = iConv2->kernel[y][x]; 381 double n = normConv->kernel[y][x]; 376 382 float i1 = image1->kernel[y][x]; 377 383 float i2 = image2->kernel[y][x]; … … 381 387 double ai1 = a * i1; 382 388 double bi1 = b * i1; 389 390 double an = a * n; 391 double bn = b * n; 383 392 384 393 if (weight) { … … 391 400 b *= wtVal; 392 401 i2 *= wtVal; 402 403 an *= wtVal; 404 bn *= wtVal; 393 405 } 394 406 if (window) { … … 401 413 b *= wtVal; 402 414 i2 *= wtVal; 415 416 an *= wtVal; 417 bn *= wtVal; 403 418 } 404 419 sumAI2 += ai2; … … 409 424 sumB += b; 410 425 sumI2 += i2; 426 427 sumAN += an; 428 sumBN += bn; 411 429 } 412 430 } … … 420 438 double b = sumB * poly[iTerm]; 421 439 440 double an = sumAN * poly[iTerm]; 441 double bn = sumBN * poly[iTerm]; 442 422 443 if ((mode & PM_SUBTRACTION_EQUATION_NORM) && (mode & PM_SUBTRACTION_EQUATION_KERNELS)) { 423 matrix->data.F64[iIndex][normIndex] = ai1; 424 matrix->data.F64[normIndex][iIndex] = ai1; 425 matrix->data.F64[iIndex + numParams][normIndex] = bi1; 426 matrix->data.F64[normIndex][iIndex + numParams] = bi1; 444 // matrix->data.F64[iIndex][normIndex] = ai1; 445 // matrix->data.F64[normIndex][iIndex] = ai1; 446 // matrix->data.F64[iIndex + numParams][normIndex] = bi1; 447 // matrix->data.F64[normIndex][iIndex + numParams] = bi1; 448 matrix->data.F64[iIndex][normIndex] = an; 449 matrix->data.F64[normIndex][iIndex] = an; 450 matrix->data.F64[iIndex + numParams][normIndex] = bn; 451 matrix->data.F64[normIndex][iIndex + numParams] = bn; 427 452 } 428 453 if ((mode & PM_SUBTRACTION_EQUATION_BG) && (mode & PM_SUBTRACTION_EQUATION_KERNELS)) { … … 453 478 double sumI1I2 = 0.0; // Sum of I_1.I_2 (for vector, normalisation) 454 479 double normI1 = 0.0, normI2 = 0.0; // Sum of I_1 and I_2 within the normalisation window 480 481 double sumN = 0.0; // Matrix: bg*norm 482 double sumN2 = 0.0; // Matrix: norm*norm 483 double sumNI2 = 0.0; // Vector: I2*norm 484 455 485 for (int y = - footprint; y <= footprint; y++) { 456 486 for (int x = - footprint; x <= footprint; x++) { … … 461 491 double one = 1.0; 462 492 double i1i2 = i1 * i2; 493 494 double n = normConv->kernel[y][x]; 495 double n2 = n * n; 496 double ni2 = n * i2; 463 497 464 498 if (PS_SQR(x) + PS_SQR(y) <= PS_SQR(normWindow)) { … … 474 508 i2 *= wtVal; 475 509 i1i2 *= wtVal; 510 511 n *= wtVal; 512 n2 *= wtVal; 513 ni2 *= wtVal; 476 514 } 477 515 if (window) { … … 482 520 i2 *= wtVal; 483 521 i1i2 *= wtVal; 522 523 n *= wtVal; 524 n2 *= wtVal; 525 ni2 *= wtVal; 484 526 } 485 527 sumI1 += i1; … … 488 530 sumI2 += i2; 489 531 sumI1I2 += i1i2; 532 533 sumN += n; 534 sumN2 += n2; 535 sumNI2 += ni2; 490 536 } 491 537 } … … 496 542 497 543 if (mode & PM_SUBTRACTION_EQUATION_NORM) { 498 matrix->data.F64[normIndex][normIndex] = sumI1I1; 499 vector->data.F64[normIndex] = sumI1I2; 544 // matrix->data.F64[normIndex][normIndex] = sumI1I1; 545 // vector->data.F64[normIndex] = sumI1I2; 546 matrix->data.F64[normIndex][normIndex] = sumN2; 547 vector->data.F64[normIndex] = sumNI2; 548 500 549 } 501 550 if (mode & PM_SUBTRACTION_EQUATION_BG) { … … 504 553 } 505 554 if ((mode & PM_SUBTRACTION_EQUATION_NORM) && (mode & PM_SUBTRACTION_EQUATION_BG)) { 506 matrix->data.F64[bgIndex][normIndex] = sumI1; 507 matrix->data.F64[normIndex][bgIndex] = sumI1; 555 // matrix->data.F64[bgIndex][normIndex] = sumI1; 556 // matrix->data.F64[normIndex][bgIndex] = sumI1; 557 matrix->data.F64[bgIndex][normIndex] = sumN; 558 matrix->data.F64[normIndex][bgIndex] = sumN; 508 559 } 509 560 return true; … … 729 780 stamp->image1, stamp->image2, 730 781 weight, window, stamp->convolutions1, stamp->convolutions2, 731 kernels, polyValues, footprint, stamps->normWindow, mode); 782 stamp->normConv, kernels, polyValues, footprint, 783 stamps->normWindow, mode); 732 784 break; 733 785 default: -
branches/pap/psModules/src/imcombine/pmSubtractionKernels.c
r26686 r26717 15 15 16 16 #define RINGS_BUFFER 10 // Buffer size for RINGS data 17 18 #define NORM_WIDTH 7.5 17 19 18 20 // Free function for pmSubtractionKernels … … 30 32 psFree(kernels->solution2); 31 33 psFree(kernels->sampleStamps); 34 psFree(kernels->norm); 32 35 } 33 36 … … 242 245 243 246 if (zeroNull) { 244 preCalc->kernel->kernel[0][0] -= 1.0; 247 // preCalc->kernel->kernel[0][0] -= 1.0; 248 for (int v = -size; v <= size; v++) { 249 for (int u = -size; u <= size; u++) { 250 preCalc->kernel->kernel[v][u] -= kernels->norm->kernel[v][u]; 251 } 252 } 245 253 } 246 254 … … 582 590 kernels->fMinResMean = NAN; 583 591 kernels->fMinResStdev = NAN; 592 593 kernels->norm = psKernelAlloc(-size, size, -size, size); 594 double sumNorm = 0.0; 595 float sigma = NORM_WIDTH / 2.35; 596 for (int y = -size; y <= size; y++) { 597 for (int x = -size; x <= size; x++) { 598 float z = 0.5 * (PS_SQR(x) + PS_SQR(y)) / PS_SQR(sigma); 599 sumNorm += kernels->norm->kernel[y][x] = expf(-z); 600 } 601 } 602 for (int y = -size; y <= size; y++) { 603 for (int x = -size; x <= size; x++) { 604 kernels->norm->kernel[y][x] /= sumNorm; 605 } 606 } 584 607 585 608 return kernels; -
branches/pap/psModules/src/imcombine/pmSubtractionKernels.h
r26593 r26717 12 12 PM_SUBTRACTION_KERNEL_ISIS_RADIAL, ///< ISIS + higher-order radial Hermitians 13 13 PM_SUBTRACTION_KERNEL_HERM, ///< Hermitian polynomial kernels 14 PM_SUBTRACTION_KERNEL_DECONV_HERM, ///< Deconvolved Hermitian polynomial kernels14 PM_SUBTRACTION_KERNEL_DECONV_HERM, ///< Deconvolved Hermitian polynomial kernels 15 15 PM_SUBTRACTION_KERNEL_SPAM, ///< Summed Pixels for Advanced Matching --- summed delta functions 16 16 PM_SUBTRACTION_KERNEL_FRIES, ///< Fibonacci Radius Increases Excellence of Subtraction … … 37 37 psVector *uStop, *vStop; ///< Width of kernel element (SPAM,FRIES only) 38 38 psArray *preCalc; ///< Array of images containing pre-calculated kernel (for ISIS, HERM or DECONV_HERM) 39 psKernel *norm; ///< Normalisation component 39 40 float penalty; ///< Penalty for wideness 40 41 psVector *penalties; ///< Penalty for each kernel component … … 49 50 float mean, rms; ///< Mean and RMS of chi^2 from stamps 50 51 int numStamps; ///< Number of good stamps 51 float fSigResMean; ///< mean fractional stdev of residuals52 float fSigResStdev; ///< stdev of fractional stdev of residuals53 float fMaxResMean; ///< mean fractional positive swing in residuals54 float fMaxResStdev; ///< stdev of fractional positive swing in residuals55 float fMinResMean; ///< mean fractional negative swing in residuals56 float fMinResStdev; ///< stdev of fractional negative swing in residuals57 psArray *sampleStamps; ///< array of brightest set of stamps for output visualizations52 float fSigResMean; ///< mean fractional stdev of residuals 53 float fSigResStdev; ///< stdev of fractional stdev of residuals 54 float fMaxResMean; ///< mean fractional positive swing in residuals 55 float fMaxResStdev; ///< stdev of fractional positive swing in residuals 56 float fMinResMean; ///< mean fractional negative swing in residuals 57 float fMinResStdev; ///< stdev of fractional negative swing in residuals 58 psArray *sampleStamps; ///< array of brightest set of stamps for output visualizations 58 59 } pmSubtractionKernels; 59 60 60 61 // pmSubtractionKernels->preCalc is an array of pmSubtractionKernelPreCalc structures 61 62 typedef struct { 62 psVector *uCoords; // used by RINGS63 psVector *vCoords; // used by RINGS64 psVector *poly; // used by RINGS65 66 psVector *xKernel; // used by ISIS, HERM, DECONV_HERM67 psVector *yKernel; // used by ISIS, HERM, DECONV_HERM68 psKernel *kernel; // used by ISIS, HERM, DECONV_HERM63 psVector *uCoords; // used by RINGS 64 psVector *vCoords; // used by RINGS 65 psVector *poly; // used by RINGS 66 67 psVector *xKernel; // used by ISIS, HERM, DECONV_HERM 68 psVector *yKernel; // used by ISIS, HERM, DECONV_HERM 69 psKernel *kernel; // used by ISIS, HERM, DECONV_HERM 69 70 } pmSubtractionKernelPreCalc; 70 71 … … 168 169 pmSubtractionKernelPreCalc *pmSubtractionKernelPreCalcAlloc( 169 170 pmSubtractionKernelsType type, ///< type of kernel to allocate (not all can be pre-calculated) 170 int uOrder, ///< order in x-direction171 int vOrder, ///< order in x-direction172 int size, ///< Half-size of the kernel173 float sigma ///< sigma of gaussian kernel171 int uOrder, ///< order in x-direction 172 int vOrder, ///< order in x-direction 173 int size, ///< Half-size of the kernel 174 float sigma ///< sigma of gaussian kernel 174 175 ); 175 176 … … 202 203 /// Generate ISIS + RADIAL_HERM kernels 203 204 pmSubtractionKernels *pmSubtractionKernelsISIS_RADIAL(int size, ///< Half-size of the kernel 204 int spatialOrder, ///< Order of spatial variations205 const psVector *fwhms, ///< Gaussian FWHMs206 const psVector *orders, ///< Polynomial order of gaussians207 float penalty, ///< Penalty for wideness208 pmSubtractionMode mode ///< Mode for subtraction205 int spatialOrder, ///< Order of spatial variations 206 const psVector *fwhms, ///< Gaussian FWHMs 207 const psVector *orders, ///< Polynomial order of gaussians 208 float penalty, ///< Penalty for wideness 209 pmSubtractionMode mode ///< Mode for subtraction 209 210 ); 210 211 … … 220 221 /// Generate DECONV_HERM kernels 221 222 pmSubtractionKernels *pmSubtractionKernelsDECONV_HERM(int size, ///< Half-size of the kernel 222 int spatialOrder, ///< Order of spatial variations223 const psVector *fwhms, ///< Gaussian FWHMs224 const psVector *orders, ///< order of hermitian polynomials225 float penalty, ///< Penalty for wideness226 pmSubtractionMode mode ///< Mode for subtraction223 int spatialOrder, ///< Order of spatial variations 224 const psVector *fwhms, ///< Gaussian FWHMs 225 const psVector *orders, ///< order of hermitian polynomials 226 float penalty, ///< Penalty for wideness 227 pmSubtractionMode mode ///< Mode for subtraction 227 228 ); 228 229 -
branches/pap/psModules/src/imcombine/pmSubtractionStamps.c
r26703 r26717 312 312 stamp->vector = NULL; 313 313 stamp->norm = NAN; 314 stamp->normConv = NULL; 314 315 315 316 return stamp; -
branches/pap/psModules/src/imcombine/pmSubtractionStamps.h
r26703 r26717 83 83 psVector *vector; ///< Least-squares vector, or NULL 84 84 double norm; ///< Normalisation difference 85 psKernel *normConv; ///< Convolution of normalisation 85 86 pmSubtractionStampStatus status; ///< Status of stamp 86 87 } pmSubtractionStamp;
Note:
See TracChangeset
for help on using the changeset viewer.
