Changeset 21382
- Timestamp:
- Feb 6, 2009, 12:39:15 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageCovariance.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageCovariance.c
r21324 r21382 4 4 5 5 #include <stdio.h> 6 #include <stdlib.h> 6 7 #include <limits.h> 7 8 #include <string.h> … … 181 182 182 183 int xMin = covar->xMin, xMax = covar->xMax, yMin = covar->yMin, yMax = covar->yMax; // Range 184 int maxRadius = PS_MAX(PS_MAX(PS_MAX(xMax, yMax), -xMin), yMin); // Maximum radius of covariance matrix 183 185 184 186 double sum = 0.0; // Sum of covariance 187 psVector *radiusSum = psVectorAlloc(maxRadius, PS_TYPE_F64); // Totals within (square) radius 188 psVectorInit(radiusSum, 0.0); 185 189 for (int y = yMin; y <= yMax; y++) { 186 190 for (int x = xMin; x <= xMax; x++) { 187 sum += covar->kernel[y][x]; 191 int radius = PS_MAX(abs(x), abs(y)); // Squarish radius 192 radiusSum->data.F64[radius] += fabsf(covar->kernel[y][x]); 193 sum += fabsf(covar->kernel[y][x]); 188 194 } 189 195 } … … 191 197 // Determine radius for truncation 192 198 double threshold = (1.0 - frac) * sum; // Threshold for truncation 193 int maxRadius = PS_MAX(PS_MAX(PS_MAX(xMax, yMax), -xMin), yMin); // Maximum radius of covariance matrix194 199 double enclosed = 0.0; // Enclosed value 195 200 int radius; // Radius at which to truncate 196 201 for (radius = 0; radius <= maxRadius && enclosed < threshold; radius++) { 197 // Not so efficient to execute, but easy to code; it should be fast anyway 198 enclosed = 0.0; 199 for (int y = PS_MAX(yMin, -radius); y <= PS_MIN(yMax, radius); y++) { 200 for (int x = PS_MAX(xMin, -radius); x <= PS_MIN(xMax, radius); x++) { 201 enclosed += covar->kernel[y][x]; 202 } 203 } 204 } 202 enclosed += radiusSum->data.F64[radius]; 203 } 204 psFree(radiusSum); 205 205 206 206 // Generate truncated version
Note:
See TracChangeset
for help on using the changeset viewer.
