Changeset 26704
- Timestamp:
- Jan 28, 2010, 4:23:00 AM (16 years ago)
- Location:
- branches/eam_branches/20091201/psLib/src/imageops
- Files:
-
- 2 edited
-
psImageCovariance.c (modified) (2 diffs)
-
psImageCovariance.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psLib/src/imageops/psImageCovariance.c
r25994 r26704 24 24 } 25 25 26 float psImageCovarianceCalculateFactor(const psKernel *kernel, const psKernel *covariance) 27 { 28 psKernel *covar; // Covariance matrix to use 29 if (covariance) { 30 covar = psMemIncrRefCounter((psKernel*)covariance); // Casting away const 31 } else { 32 covar = psImageCovarianceNone(); 33 } 34 35 // Check for non-finite elements 36 for (int y = kernel->yMin; y <= kernel->yMax; y++) { 37 for (int x = kernel->xMin; x <= kernel->xMax; x++) { 38 if (!isfinite(kernel->kernel[y][x])) { 39 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 40 "Non-finite covariance matrix element in kernel at %d,%d", x, y); 41 psFree(covar); 42 return NAN; 43 } 44 } 45 } 46 for (int y = covar->yMin; y <= covar->yMax; y++) { 47 for (int x = covar->xMin; x <= covar->xMax; x++) { 48 if (!isfinite(covar->kernel[y][x])) { 49 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 50 "Non-finite covariance matrix element in covariance matrix at %d,%d", x, y); 51 psFree(covar); 52 return NAN; 53 } 54 } 55 } 56 57 int x = 0, y = 0; // Coordinates on the output covariance matrix 58 59 // Range for v 60 int vMin = PS_MAX(kernel->yMin + covar->yMin, y + kernel->yMin); 61 int vMax = PS_MIN(kernel->yMax + covar->yMax, y + kernel->yMax); 62 // Range for u 63 int uMin = PS_MAX(kernel->xMin + covar->xMin, x + kernel->xMin); 64 int uMax = PS_MIN(kernel->xMax + covar->xMax, x + kernel->xMax); 65 66 double sum = 0.0; // Sum for value of covariance matrix at (x,y) 67 for (int v = vMin; v <= vMax; v++) { 68 // Range for q 69 int qMin = PS_MAX(v + covar->yMin, kernel->yMin); 70 int qMax = PS_MIN(v + covar->yMax, kernel->yMax); 71 for (int u = uMin; u <= uMax; u++) { 72 // Range for p 73 int pMin = PS_MAX(u + covar->xMin, kernel->xMin); 74 int pMax = PS_MIN(u + covar->xMax, kernel->xMax); 75 76 double xyuvValue = kernel->kernel[v-y][u-x]; // Value for (x,y) --> (u,v) 77 78 double uvpqValue = 0.0; // Value for (u,v) --> (p,q) --> (0,0) 79 for (int q = qMin; q <= qMax; q++) { 80 for (int p = pMin; p <= pMax; p++) { 81 uvpqValue += (double)covar->kernel[q-v][p-u] * (double)kernel->kernel[q][p]; 82 } 83 } 84 sum += xyuvValue * uvpqValue; 85 } 86 } 87 88 psFree(covar); 89 return sum; 90 } 26 91 27 92 psKernel *psImageCovarianceCalculate(const psKernel *kernel, const psKernel *covariance) … … 219 284 220 285 for (int y = covar->yMin; y <= covar->yMax; y++) { 221 if (y < -radius) continue;222 if (y > +radius) continue;223 for (int x = covar->xMin; x <= covar->xMax; x++) {224 if (x < -radius) continue;225 if (x > +radius) continue;226 227 if (hypot(x, y) > radius) continue;228 229 psAssert (isfinite(covar->kernel[y][x]), "invalid NAN in covariance matrix");230 Sum += covar->kernel[y][x];231 }286 if (y < -radius) continue; 287 if (y > +radius) continue; 288 for (int x = covar->xMin; x <= covar->xMax; x++) { 289 if (x < -radius) continue; 290 if (x > +radius) continue; 291 292 if (hypot(x, y) > radius) continue; 293 294 psAssert (isfinite(covar->kernel[y][x]), "invalid NAN in covariance matrix"); 295 Sum += covar->kernel[y][x]; 296 } 232 297 } 233 298 -
branches/eam_branches/20091201/psLib/src/imageops/psImageCovariance.h
r25994 r26704 47 47 ); 48 48 49 /// Return the pixel-to-pixel covariance factor following calculation 50 /// 51 /// This doesn't require calculation of the entire covariance matrix, so is much faster. 52 float psImageCovarianceCalculateFactor( 53 const psKernel *kernel, ///< Convolution kernel 54 const psKernel *covariance ///< Current covariance pseudo-matrix 55 ); 56 57 49 58 /// Return the covariance factor for an aperture of a given radius 50 59 float psImageCovarianceFactorForAperture(const psKernel *covar, float radius);
Note:
See TracChangeset
for help on using the changeset viewer.
