Changeset 28006 for trunk/psLib/src/imageops/psImageCovariance.c
- Timestamp:
- May 18, 2010, 2:34:09 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psLib/src/imageops/psImageCovariance.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/pap (added) merged: 27707-27709,27726-27727,27732-27733,27787,27791-27792,27933,28003-28005 /branches/pap_delete removed
- Property svn:mergeinfo changed
-
trunk/psLib/src/imageops/psImageCovariance.c
r27702 r28006 11 11 #include "psMemory.h" 12 12 #include "psConstants.h" 13 #include "psImageStructManip.h" 14 #include "psImagePixelManip.h" 13 15 #include "psImageConvolve.h" 14 16 #include "psTrace.h" … … 16 18 #include "psScalar.h" 17 19 #include "psThread.h" 20 #include "psImageInterpolate.h" 18 21 19 22 #include "psImageCovariance.h" 20 23 21 24 static bool threaded = false; // Run threaded? 22 23 25 24 26 psKernel *psImageCovarianceNone(void) … … 530 532 531 533 534 psKernel *psImageCovarianceScale(const psKernel *in, float scale) 535 { 536 // Trivial cases 537 if (!in) { 538 psKernel *out = psKernelAlloc(0, 0, 0, 0); // Output covariance 539 out->kernel[0][0] = 1.0; 540 return out; 541 } 542 PS_ASSERT_KERNEL_NON_NULL(in, NULL); 543 if (scale == 1.0) { 544 psImage *copy = psImageCopy(NULL, in->image, PS_TYPE_F32); // Copy of input covariance 545 psKernel *out = psKernelAllocFromImage(copy, -in->xMin, -in->yMin); // Output covariance 546 psFree(copy); 547 return out; 548 } 549 550 int xMinIn = in->xMin, xMaxIn = in->xMax, yMinIn = in->yMin, yMaxIn = in->yMax; // Input size 551 int xMinOut = (float)xMinIn / scale - 0.5, xMaxOut = (float)xMaxIn / scale + 0.5; // Output size in x 552 int yMinOut = (float)yMinIn / scale - 0.5, yMaxOut = (float)yMaxIn / scale + 0.5; // Output size in y 553 554 // Over-fill the covariance matrix so we're not troubled by edge effects 555 psKernel *overfill = psKernelAlloc(xMinIn - 1, xMaxIn + 1, yMinIn - 1, yMaxIn + 1); // Overfilled covar 556 psImageInit(overfill->image, 0.0); 557 int numOverlay = (xMaxIn - xMinIn + 1) * (yMaxIn - yMinIn + 1); // Number of pixels to overlay 558 if (psImageOverlaySection(overfill->image, in->image, 1, 1, "=") != numOverlay) { 559 psError(psErrorCodeLast(), false, "Unable to overfill covariance matrix."); 560 psFree(overfill); 561 return NULL; 562 } 563 564 psImageInterpolation *interp = psImageInterpolationAlloc(PS_INTERPOLATE_BILINEAR, overfill->image, 565 NULL, NULL, 0, NAN, NAN, 0xFF, 0xFF, 566 0.0, 0); // Interpolation 567 psFree(overfill); 568 569 // In transforming the positions, we get +0.5 to account for the centre of the pixels being at 0.5 570 // and +1 to account for the overfill. 571 572 psKernel *out = psKernelAlloc(xMinOut, xMaxOut, yMinOut, yMaxOut); // Output covariance 573 for (int y = yMinOut; y <= yMaxOut; y++) { 574 float yIn = y * scale + 0.5 - yMinIn + 1; // Position on input image (not the kernel) 575 for (int x = xMinOut; x <= xMaxOut; x++) { 576 float xIn = x * scale + 0.5 - xMinIn + 1; // Position on input (not the kernel) 577 double value; // Value on output 578 if (!psImageInterpolate(&value, NULL, NULL, xIn, yIn, interp)) { 579 psError(psErrorCodeLast(), false, "Unable to interpolate kernel."); 580 return false; 581 } 582 out->kernel[y][x] = value; 583 } 584 } 585 586 psFree(interp); 587 588 return out; 589 } 590 591 532 592 bool psImageCovarianceSetThreads(bool set) 533 593 {
Note:
See TracChangeset
for help on using the changeset viewer.
