IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21382


Ignore:
Timestamp:
Feb 6, 2009, 12:39:15 PM (17 years ago)
Author:
Paul Price
Message:

More efficient determination of truncation radius.
Sums need to be of absolute values, since covariance can be negative.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageCovariance.c

    r21324 r21382  
    44
    55#include <stdio.h>
     6#include <stdlib.h>
    67#include <limits.h>
    78#include <string.h>
     
    181182
    182183    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
    183185
    184186    double sum = 0.0;                   // Sum of covariance
     187    psVector *radiusSum = psVectorAlloc(maxRadius, PS_TYPE_F64); // Totals within (square) radius
     188    psVectorInit(radiusSum, 0.0);
    185189    for (int y = yMin; y <= yMax; y++) {
    186190        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]);
    188194        }
    189195    }
     
    191197    // Determine radius for truncation
    192198    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 matrix
    194199    double enclosed = 0.0;              // Enclosed value
    195200    int radius;                         // Radius at which to truncate
    196201    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);
    205205
    206206    // Generate truncated version
Note: See TracChangeset for help on using the changeset viewer.