Changeset 27709
- Timestamp:
- Apr 16, 2010, 5:26:35 PM (16 years ago)
- File:
-
- 1 edited
-
branches/pap/ppSub/src/ppSubReadoutSubtract.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/ppSub/src/ppSubReadoutSubtract.c
r27708 r27709 50 50 outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask); 51 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. 52 // Combining the variance is not straight-forward. The problem is, we're representing the variance by a 53 // variance map and a covariance pseudo-matrix, and we cannot simply add them and get the correct result, 54 // because they don't combine nicely. It's like we want dD = aA + bB, but the upper- and lower-case 55 // variables can't be merged. Our solution is to pull the normalisation of the covariance pseudo-matrices 56 // into the variance map, sum the scaled variance maps and (weighted) average the covariance 57 // pseudo-matrices. It's not perfectly correct, but it's gotta be good enough. 59 58 60 59 // Measure the variance scales … … 89 88 psFree(covarWeights); 90 89 90 // Restore the scales, in case someone cares to look at the noise in the convolved images 91 psBinaryOp(minuend->covariance->image, minuend->covariance->image, "*", 92 psScalarAlloc(minuendSum, PS_TYPE_F32)); 93 psBinaryOp(subtrahend->covariance->image, subtrahend->covariance->image, "*", 94 psScalarAlloc(subtrahendSum, PS_TYPE_F32)); 95 91 96 // Combine the variance maps 92 97 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 psImage *outVar = outRO->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Output variance map 99 psImage *minuendVariance = minuend->variance, *subtrahendVariance = subtrahend->variance; // Variance maps 98 100 for (int y = 0; y < numRows; y++) { 99 101 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); 102 outVar->data.F32[y][x] = minuendVariance->data.F32[y][x] * minuendSum + 103 subtrahendVariance->data.F32[y][x] * subtrahendSum; 103 104 } 104 105 }
Note:
See TracChangeset
for help on using the changeset viewer.
