Changeset 30383 for branches/eam_branches/ipp-20101205/psModules/src/imcombine/pmSubtractionEquation.c
- Timestamp:
- Jan 26, 2011, 5:21:42 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/psModules/src/imcombine/pmSubtractionEquation.c
r30333 r30383 1072 1072 // SINGLE solution 1073 1073 # if (1) 1074 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN);1074 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-10); 1075 1075 invMatrix = psMatrixInvert(NULL, sumMatrix, NULL); 1076 1076 # endif … … 1176 1176 // DUAL solution 1177 1177 # if (1) 1178 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN);1178 solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-10); 1179 1179 invMatrix = psMatrixInvert(NULL, sumMatrix, NULL); 1180 1180 # endif … … 1306 1306 1307 1307 // given the convolved image(s) and the residual image, calculate the second moment(s) and the chisq 1308 bool pmSubtractionChisqStats(psVector *fluxesVector, psVector *chisq Vector, psVector *momentVector, psVector *stampMask, psKernel *convolved1, psKernel *convolved2, psKernel *residual, psKernel *weight, psKernel *window) {1308 bool pmSubtractionChisqStats(psVector *fluxesVector, psVector *chisqDVector, psVector *chisqRVector, psVector *momentVector, psVector *stampMask, psKernel *convolved1, psKernel *convolved2, psKernel *difference, psKernel *residual, psKernel *weight, psKernel *window) { 1309 1309 1310 1310 # ifndef USE_WEIGHT … … 1316 1316 1317 1317 int npix = 0; 1318 float chisq = 0; 1318 float chisqR = 0; 1319 float chisqD = 0; 1319 1320 1320 1321 // get the chisq 1321 1322 for (int y = residual->yMin; y <= residual->yMax; y++) { 1322 1323 for (int x = residual->xMin; x <= residual->xMax; x++) { 1323 float value = PS_SQR(residual->kernel[y][x]);1324 float valueR = PS_SQR(residual->kernel[y][x]); 1324 1325 if (weight) { 1325 value *= weight->kernel[y][x];1326 valueR *= weight->kernel[y][x]; 1326 1327 } 1327 // XXX NOTE: do NOT apply the window to the chisq portions of the calculation 1328 if (false && window) { 1329 value *= window->kernel[y][x]; 1328 // XXX NOTE: do NOT apply the window to the chisq portions of the calculation (that would bias the chisq) 1329 chisqR += valueR; 1330 1331 float valueD = PS_SQR(difference->kernel[y][x]); 1332 if (weight) { 1333 valueD *= weight->kernel[y][x]; 1330 1334 } 1331 chisq += value;1335 chisqD += valueD; 1332 1336 npix ++; 1333 1337 } 1334 1338 } 1335 psVectorAppend(chisqVector, chisq / npix); 1339 psVectorAppend(chisqRVector, chisqR / npix); 1340 psVectorAppend(chisqDVector, chisqD / npix); 1336 1341 1337 1342 float value1 = 0; … … 1430 1435 int Nelem = fluxesVector->n - 1; 1431 1436 bool valid = true; 1432 valid &= isfinite(chisq Vector->data.F32[Nelem]);1437 valid &= isfinite(chisqRVector->data.F32[Nelem]); 1433 1438 valid &= isfinite(fluxesVector->data.F32[Nelem]); 1434 1439 valid &= isfinite(momentVector->data.F32[Nelem]); … … 1453 1458 // XXX need to save these somewhere 1454 1459 psVector *fluxes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1455 psVector *chisq = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1460 psVector *chisqD = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1461 psVector *chisqR = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1456 1462 psVector *moments = psVectorAllocEmpty(stamps->num, PS_TYPE_F32); 1457 1463 psVector *stampMask = psVectorAllocEmpty(stamps->num, PS_TYPE_VECTOR_MASK); … … 1464 1470 // storage for the image (convolved2 is not used in SINGLE mode) 1465 1471 psKernel *residual = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1472 psKernel *difference = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1466 1473 psKernel *convolved1 = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image 1467 1474 psKernel *convolved2 = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image … … 1474 1481 psVectorAppend(moments, NAN); 1475 1482 psVectorAppend(fluxes, NAN); 1476 psVectorAppend(chisq, NAN); 1483 psVectorAppend(chisqD, NAN); 1484 psVectorAppend(chisqR, NAN); 1477 1485 psVectorAppend(stampMask, 0x01); 1478 1486 continue; … … 1487 1495 // Calculate residuals 1488 1496 psImageInit(residual->image, 0.0); 1497 psImageInit(difference->image, 0.0); 1489 1498 1490 1499 psKernel *weight = NULL; … … 1537 1546 } 1538 1547 1539 // generate the residual image 1548 // Generate the difference, residual, and convolved source images. Note the we 1549 // accumulate the convolution of (A-B), so we need to replace it to generate the 1550 // images of the convolved source image. 1540 1551 for (int y = - footprint; y <= footprint; y++) { 1541 1552 for (int x = - footprint; x <= footprint; x++) { 1553 difference->kernel[y][x] = target->kernel[y][x] - source->kernel[y][x] * norm - background; 1554 residual->kernel[y][x] = difference->kernel[y][x] - convolved1->kernel[y][x]; 1542 1555 convolved1->kernel[y][x] += source->kernel[y][x] * norm; 1543 residual->kernel[y][x] = target->kernel[y][x] - convolved1->kernel[y][x] - background;1544 1556 } 1545 1557 } 1558 1546 1559 // XXX if we want to have a weight and window, we'll need to pass through to here 1547 pmSubtractionChisqStats(fluxes, chisq , moments, stampMask, convolved1, NULL, residual, weight, window);1560 pmSubtractionChisqStats(fluxes, chisqD, chisqR, moments, stampMask, convolved1, NULL, difference, residual, weight, window); 1548 1561 1549 1562 } else { … … 1574 1587 } 1575 1588 1589 // Generate the difference, residual, and convolved source images. Note the we 1590 // accumulate the convolutions of (A-B), so we need to replace (A or B) to generate 1591 // the images of the convolved source images. 1576 1592 for (int y = - footprint; y <= footprint; y++) { 1577 1593 for (int x = - footprint; x <= footprint; x++) { 1594 difference->kernel[y][x] = image2->kernel[y][x] - image1->kernel[y][x] * norm - background; 1595 residual->kernel[y][x] = difference->kernel[y][x] + convolved2->kernel[y][x] - convolved1->kernel[y][x]; 1578 1596 convolved1->kernel[y][x] += image1->kernel[y][x] * norm; 1579 1597 convolved2->kernel[y][x] += image2->kernel[y][x]; 1580 residual->kernel[y][x] = convolved2->kernel[y][x] - convolved1->kernel[y][x] - background;1581 1598 } 1582 1599 } … … 1589 1606 } 1590 1607 1591 pmSubtractionChisqStats(fluxes, chisq , moments, stampMask, convolved1, convolved2, residual, weight, window);1608 pmSubtractionChisqStats(fluxes, chisqD, chisqR, moments, stampMask, convolved1, convolved2, difference, residual, weight, window); 1592 1609 } 1593 1610 } … … 1595 1612 // find the mean chisq and mean moment 1596 1613 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 1597 psVectorStats (stats, chisq, NULL, stampMask, 0xff); 1598 float chisqValue = stats->sampleMean; 1614 psVectorStats (stats, chisqD, NULL, stampMask, 0xff); 1615 float chisqDValue = stats->sampleMean; 1616 1617 psStatsInit(stats); 1618 psVectorStats (stats, chisqR, NULL, stampMask, 0xff); 1619 float chisqRValue = stats->sampleMean; 1599 1620 1600 1621 psStatsInit(stats); … … 1637 1658 // penalized by increasing the score somewhat. the 0.01 value is not well-chosen. 1638 1659 float orderFactor = 0.01 * kernels->spatialOrder; 1639 float score = 2.0 * chisq Value / (sumKernel1 + sumKernel2) + orderFactor;1640 psLogMsg("psModules.imcombine", PS_LOG_INFO, "chisq: %6.3f, moment: %6.3f, sumKernel_1: %6.3f, sumKernel_2, score: %6.3f: %6.3f\n", chisqValue, momentValue, sumKernel1, sumKernel2, score);1660 float score = 2.0 * chisqRValue / (sumKernel1 + sumKernel2) + orderFactor; 1661 psLogMsg("psModules.imcombine", PS_LOG_INFO, "chisq: %6.3f, chisqD: %6.3f, moment: %6.3f, sumKernel_1: %6.3f, sumKernel_2, score: %6.3f: %6.3f\n", chisqRValue, chisqDValue, momentValue, sumKernel1, sumKernel2, score); 1641 1662 1642 1663 // save this result if it is the first or the best (skip if bestMatch is NULL) … … 1663 1684 match->nGood = nGood; 1664 1685 match->fluxes = psMemIncrRefCounter(fluxes); 1665 match->chisq = psMemIncrRefCounter(chisq );1686 match->chisq = psMemIncrRefCounter(chisqR); 1666 1687 match->moments = psMemIncrRefCounter(moments); 1667 1688 match->stampMask = psMemIncrRefCounter(stampMask); … … 1669 1690 } 1670 1691 1671 pmSubtractionVisualPlotChisqAndMoments(fluxes, chisq , moments);1692 pmSubtractionVisualPlotChisqAndMoments(fluxes, chisqR, moments); 1672 1693 1673 1694 psFree(stats); 1674 psFree(chisq); 1695 psFree(chisqR); 1696 psFree(chisqD); 1675 1697 psFree(fluxes); 1676 1698 psFree(moments);
Note:
See TracChangeset
for help on using the changeset viewer.
