Changeset 28152
- Timestamp:
- May 27, 2010, 7:34:23 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageCovariance.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageCovariance.c
r28151 r28152 576 576 for (int x = xMinOut; x <= xMaxOut; x++) { 577 577 float xIn = x * scale + 0.5 - xMinIn + 1; // Position on input (not the kernel) 578 578 579 double value; // Value on output 579 580 if (!psImageInterpolate(&value, NULL, NULL, xIn, yIn, interp)) { … … 586 587 psFree(interp); 587 588 589 // Problem: the interpolation has introduced power into the covariance matrix that shouldn't be there. We 590 // can't scale the sum of the matrix because that would throw off the central value and affect the noise 591 // calculation for this image. But we can't scale just by the central value because that would throw off 592 // the noise calculation for convolutions of this image. We choose to scale by the sum of the non-central 593 // elements. This is almost having the best of both worlds. 594 588 595 double inSum = 0.0; // Sum of covariance 589 596 for (int y = yMinIn; y <= yMaxIn; y++) { … … 593 600 } 594 601 595 float norm = inSum / PS_SQR(scale) / outSum; // Renormalisation (to remove errors in interp.)602 float norm = (inSum - in->kernel[0][0]) / (outSum - out->kernel[0][0]) / PS_SQR(scale); // Renormalisation 596 603 for (int y = yMinOut; y <= yMaxOut; y++) { 597 604 for (int x = xMinOut; x <= xMaxOut; x++) { 598 out->kernel[y][x] *= norm; 605 if (x != 0 && y != 0) { 606 out->kernel[y][x] *= norm; 607 } 599 608 } 600 609 }
Note:
See TracChangeset
for help on using the changeset viewer.
