Changeset 27708
- Timestamp:
- Apr 16, 2010, 12:52:37 PM (16 years ago)
- Location:
- branches/pap
- Files:
-
- 1 edited
- 1 copied
-
. (copied) (copied from trunk )
-
ppSub/src/ppSubReadoutSubtract.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/ppSub/src/ppSubReadoutSubtract.c
r26982 r27708 48 48 pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); 49 49 outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image); 50 if (minuend->variance && subtrahend->variance) {51 outRO->variance = (psImage*)psBinaryOp(outRO->variance, minuend->variance, "+", subtrahend->variance);52 }53 50 outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask); 54 51 52 53 // Combining the variance is tricky. The problem is, we're representing the variance by a variance map 54 // and a covariance pseudo-matrix, and we cannot simply add them and get the correct result, because they 55 // don't combine nicely. It's like we want dD = aA + bB, but the upper- and lower-case variables can't be 56 // merged. Our solution is to combine the variance maps and covariance pseudo-matrices all normalised to 57 // unity, and then scale the result by the desired variance normalisation. It's not perfectly correct, 58 // but it's gotta be good enough. 59 60 // Measure the variance scales 61 psStats *varStats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for variance images 62 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 63 psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config) | 64 pmConfigMaskGet("BLANK", config); // Bits to mask in inputs 65 psImageBackground(varStats, NULL, minuend->variance, minuend->mask, maskVal, rng); 66 float minuendVar = varStats->robustMedian; // Mean variance for minuend 67 psImageBackground(varStats, NULL, subtrahend->variance, subtrahend->mask, maskVal, rng); 68 float subtrahendVar = varStats->robustMedian; // Mean variance for subtrahend 69 psFree(varStats); 70 psFree(rng); 71 72 // Measure and apply the covariance scales 73 float minuendSum = psImageCovarianceSum(minuend->covariance); // Sum of covariance for minuend 74 float subtrahendSum = psImageCovarianceSum(subtrahend->covariance); // Sum of covariance for subtrahend 75 psBinaryOp(minuend->covariance->image, minuend->covariance->image, "/", 76 psScalarAlloc(minuendSum, PS_TYPE_F32)); 77 psBinaryOp(subtrahend->covariance->image, subtrahend->covariance->image, "/", 78 psScalarAlloc(subtrahendSum, PS_TYPE_F32)); 79 80 // Combine the scaled covariances 55 81 psArray *covars = psArrayAlloc(2); // Covariance pseudo-matrices 82 psVector *covarWeights = psVectorAlloc(2, PS_TYPE_F32); // Weights for covariances 56 83 covars->data[0] = psMemIncrRefCounter(minuend->covariance); 57 84 covars->data[1] = psMemIncrRefCounter(subtrahend->covariance); 58 outRO->covariance = psImageCovarianceAverage(covars); 85 covarWeights->data.F32[0] = minuendSum * minuendVar; 86 covarWeights->data.F32[1] = subtrahendSum * subtrahendVar; 87 outRO->covariance = psImageCovarianceAverageWeighted(covars, covarWeights); 59 88 psFree(covars); 89 psFree(covarWeights); 90 91 // Combine the variance maps 92 int numCols = outRO->image->numCols, numRows = outRO->image->numRows; // Size of image 93 outRO->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 94 // The factor of 0.5 in the target variance is because there's an addition here *and* an addition below, 95 // and we only want the first to count (the second should add to 2 in the background). 96 float target = (minuendVar * minuendSum + subtrahendVar * subtrahendSum); // Target mean variance 97 fprintf(stderr, "%f %f %f %f --> %f %f\n", minuendVar, minuendSum, subtrahendVar, subtrahendSum, target, psImageCovarianceFactor(outRO->covariance)); 98 for (int y = 0; y < numRows; y++) { 99 for (int x = 0; x < numCols; x++) { 100 outRO->variance->data.F32[y][x] = target * 101 (minuend->variance->data.F32[y][x] / minuendVar + 102 subtrahend->variance->data.F32[y][x] / subtrahendVar); 103 } 104 } 105 psImageCovarianceTransfer(outRO->variance, outRO->covariance); 60 106 61 107 outRO->data_exists = true;
Note:
See TracChangeset
for help on using the changeset viewer.
