IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27697


Ignore:
Timestamp:
Apr 15, 2010, 12:59:42 PM (16 years ago)
Author:
Paul Price
Message:

psImageCovarianceSum now sums a single covariance matrix to produce a single value, rather than summing multiple covariance matrices into a single covariance matrix. This is useful when we're not interested in the pixel-to-pixel variation, but in the noise over areas of the scale of the covariance matrix (or larger).

Location:
trunk/psLib/src/imageops
Files:
2 edited

Legend:

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

    r26892 r27697  
    376376}
    377377
    378 psKernel *psImageCovarianceSum(const psArray *array)
     378float psImageCovarianceSum(const psKernel *covar)
     379{
     380    PS_ASSERT_KERNEL_NON_NULL(covar, NAN);
     381
     382    int xMin = covar->xMin, xMax = covar->xMax, yMin = covar->yMin, yMax = covar->yMax; // Range for covariance
     383    double sum = 0.0;                                                                   // Sum of covariance
     384    for (int y = yMin; y <= yMax; y++) {
     385        for (int x = xMin; x <= xMax; x++) {
     386            sum += covar->kernel[y][x];
     387        }
     388    }
     389
     390    return sum;
     391}
     392
     393
     394psKernel *psImageCovarianceAverage(const psArray *array)
    379395{
    380396    PS_ASSERT_ARRAY_NON_NULL(array, NULL);
    381397    PS_ASSERT_ARRAY_NON_EMPTY(array, NULL);
    382398
    383     int xMin = INT_MAX, xMax = INT_MIN, yMin = INT_MAX, yMax = INT_MIN; // Range for covariance
    384     int num = 0;                        // Number of good matrices to sum
    385     for (int i = 0; i < array->n; i++) {
    386         psKernel *covar = array->data[i]; // Covariance matrix
    387         if (!covar) {
    388             continue;
    389         }
    390         xMin = PS_MIN(xMin, covar->xMin);
    391         xMax = PS_MAX(xMax, covar->xMax);
    392         yMin = PS_MIN(yMin, covar->yMin);
    393         yMax = PS_MAX(yMax, covar->yMax);
    394         num++;
    395     }
    396     if (num == 0) {
    397         psError(PS_ERR_BAD_PARAMETER_SIZE, true, "No covariance matrices supplied for summation");
    398         return NULL;
    399     }
    400 
    401     psKernel *sum = psKernelAlloc(xMin, xMax, yMin, yMax); // Summed covariance
    402     for (int i = 0; i < array->n; i++) {
    403         psKernel *covar = array->data[i]; // Covariance matrix
    404         if (!covar) {
    405             continue;
    406         }
    407         for (int y = covar->yMin; y <= covar->yMax; y++) {
    408             for (int x = covar->xMin; x <= covar->xMax; x++) {
    409                 if (!isfinite(covar->kernel[y][x])) {
    410                     psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    411                             "Non-finite covariance matrix element at %d,%d for input %d",
    412                             x, y, i);
    413                     psFree(sum);
    414                     return NULL;
    415                 }
    416                 sum->kernel[y][x] += covar->kernel[y][x];
    417             }
    418         }
    419     }
    420 
    421     return sum;
    422 }
    423 
    424 
    425 psKernel *psImageCovarianceAverage(const psArray *array)
    426 {
    427     PS_ASSERT_ARRAY_NON_NULL(array, NULL);
    428     PS_ASSERT_ARRAY_NON_EMPTY(array, NULL);
    429 
    430     int num = 0;                        // Number of good matrices to average
    431     for (int i = 0; i < array->n; i++) {
    432         psKernel *covar = array->data[i]; // Covariance matrix
    433         if (covar) {
    434             num++;
    435         }
    436     }
    437     if (num == 0) {
    438         psError(PS_ERR_BAD_PARAMETER_SIZE, true, "No covariance matrices supplied for averaging.");
    439         return NULL;
    440     }
    441 
    442     psKernel *sum = psImageCovarianceSum(array); // Sum of covariances
    443     psBinaryOp(sum->image, sum->image, "/", psScalarAlloc(num, PS_TYPE_F32));
    444 
    445     return sum;
     399    psVector *weights = psVectorAlloc(array->n, PS_TYPE_F32); // Weights to apply
     400    psVectorInit(weights, 1.0);
     401    psKernel *out = psImageCovarianceAverageWeighted(array, weights);
     402    psFree(weights);
     403    return out;
    446404}
    447405
  • trunk/psLib/src/imageops/psImageCovariance.h

    r26892 r27697  
    5959float psImageCovarianceFactorForAperture(const psKernel *covar, float radius);
    6060
    61 /// Sum multiple covariance pseudo-matrices
    62 psKernel *psImageCovarianceSum(
    63     const psArray *array                ///< Array of covariance pseudo-matrices
     61/// Return the sum of the covariance pseudo-matrix
     62float psImageCovarianceSum(
     63    const psKernel *covariance          ///< Covariance pseudo-matrix
    6464    );
    6565
Note: See TracChangeset for help on using the changeset viewer.