- Timestamp:
- Jun 10, 2010, 6:28:51 PM (16 years ago)
- Location:
- branches/czw_branch/20100519
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/imageops/psImageCovariance.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20100519
- Property svn:mergeinfo changed
-
branches/czw_branch/20100519/psLib/src/imageops/psImageCovariance.c
r28006 r28304 571 571 572 572 psKernel *out = psKernelAlloc(xMinOut, xMaxOut, yMinOut, yMaxOut); // Output covariance 573 double outSum = 0.0; // Sum of covariance 573 574 for (int y = yMinOut; y <= yMaxOut; y++) { 574 575 float yIn = y * scale + 0.5 - yMinIn + 1; // Position on input image (not the kernel) 575 576 for (int x = xMinOut; x <= xMaxOut; x++) { 576 577 float xIn = x * scale + 0.5 - xMinIn + 1; // Position on input (not the kernel) 578 577 579 double value; // Value on output 578 580 if (!psImageInterpolate(&value, NULL, NULL, xIn, yIn, interp)) { … … 580 582 return false; 581 583 } 582 out->kernel[y][x] = value; 583 } 584 } 585 584 outSum += out->kernel[y][x] = value; 585 } 586 } 586 587 psFree(interp); 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 595 double inSum = 0.0; // Sum of covariance 596 for (int y = yMinIn; y <= yMaxIn; y++) { 597 for (int x = xMinIn; x <= xMaxIn; x++) { 598 inSum += in->kernel[y][x]; 599 } 600 } 601 602 float norm = (inSum - in->kernel[0][0]) / (outSum - out->kernel[0][0]) / PS_SQR(scale); // Renormalisation 603 for (int y = yMinOut; y <= yMaxOut; y++) { 604 for (int x = xMinOut; x <= xMaxOut; x++) { 605 if (x != 0 && y != 0) { 606 out->kernel[y][x] *= norm; 607 } 608 } 609 } 587 610 588 611 return out;
Note:
See TracChangeset
for help on using the changeset viewer.
