Changeset 27727 for branches/pap/ppSub/src/ppSubReadoutSubtract.c
- Timestamp:
- Apr 22, 2010, 11:07:49 AM (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
r27709 r27727 49 49 outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image); 50 50 outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask); 51 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. 51 outRO->variance = (psImage*)psBinaryOp(outRO->variance, minuend->variance, "+", subtrahend->variance); 58 52 59 53 // Measure the variance scales … … 69 63 psFree(rng); 70 64 71 // Measure and apply the covariance scales 72 float minuendSum = psImageCovarianceSum(minuend->covariance); // Sum of covariance for minuend 73 float subtrahendSum = psImageCovarianceSum(subtrahend->covariance); // Sum of covariance for subtrahend 74 psBinaryOp(minuend->covariance->image, minuend->covariance->image, "/", 75 psScalarAlloc(minuendSum, PS_TYPE_F32)); 76 psBinaryOp(subtrahend->covariance->image, subtrahend->covariance->image, "/", 77 psScalarAlloc(subtrahendSum, PS_TYPE_F32)); 78 79 // Combine the scaled covariances 65 // Combine the covariances 66 // These are weighted by the appropriate mean variance. This is probably not perfectly correct, but it 67 // does seem to reproduce the correct magnitude limit in psphot. 80 68 psArray *covars = psArrayAlloc(2); // Covariance pseudo-matrices 81 69 psVector *covarWeights = psVectorAlloc(2, PS_TYPE_F32); // Weights for covariances 82 70 covars->data[0] = psMemIncrRefCounter(minuend->covariance); 83 71 covars->data[1] = psMemIncrRefCounter(subtrahend->covariance); 84 covarWeights->data.F32[0] = minuend Sum * minuendVar;85 covarWeights->data.F32[1] = subtrahend Sum * subtrahendVar;72 covarWeights->data.F32[0] = minuendVar; 73 covarWeights->data.F32[1] = subtrahendVar; 86 74 outRO->covariance = psImageCovarianceAverageWeighted(covars, covarWeights); 87 75 psFree(covars); 88 76 psFree(covarWeights); 89 77 90 // Restore the scales, in case someone cares to look at the noise in the convolved images91 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 96 // Combine the variance maps97 int numCols = outRO->image->numCols, numRows = outRO->image->numRows; // Size of image98 psImage *outVar = outRO->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Output variance map99 psImage *minuendVariance = minuend->variance, *subtrahendVariance = subtrahend->variance; // Variance maps100 for (int y = 0; y < numRows; y++) {101 for (int x = 0; x < numCols; x++) {102 outVar->data.F32[y][x] = minuendVariance->data.F32[y][x] * minuendSum +103 subtrahendVariance->data.F32[y][x] * subtrahendSum;104 }105 }106 78 psImageCovarianceTransfer(outRO->variance, outRO->covariance); 107 79
Note:
See TracChangeset
for help on using the changeset viewer.
