IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 3, 2009, 4:55:27 PM (17 years ago)
Author:
Paul Price
Message:

Adding function to return an interpolation kernel. Intend to use this for calculating the covariance (pseudo-)matrix.

File:
1 edited

Legend:

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

    r21207 r21280  
    1111
    1212#include "psImageCovariance.h"
     13
     14psKernel *psImageCovarianceNone(void)
     15{
     16    psKernel *covar = psKernelAlloc(0, 0, 0, 0); // Covariance pseudo-matrix
     17    covar->kernel[0][0] = 1.0;
     18    return covar;
     19}
    1320
    1421
     
    2532    // where M^x is the covariance matrix for x.
    2633    // Note that the errors in f are correlated (covariance) even if the errors in x are not.
    27     //
    28     // We don't carry the entire covariance matrix for an image (the size goes as N^2, for N pixels, which
    29     // makes storage difficult; and if that's not enough, the time to do the calculation is definitely
    30     // impractical).  Since there are (generally) lots of zeros in the covariance matrix, and the same basic
    31     // pattern repeats (for background pixels), we can just carry that pattern.  We carry this in a psKernel,
    32     // since the values are the covariance between the pixel of consideration (at 0,0 in the kernel) and
    33     // neighbouring pixels.  Note that this may not be strictly correct near sources, but this is the best we
    34     // can do (and much better than most currently do).
    3534
    3635    psKernel *covar;                    // Covariance matrix to use
     
    108107float psImageCovarianceFactor(const psKernel *covariance)
    109108{
    110     return covariance ? covariance->kernel[0][0] : 1.0;
     109    return covariance ? covariance->kernel[0][0] : NAN;
    111110}
    112111
     112psKernel *psImageCovarianceAverage(const psArray *array)
     113{
     114    PS_ASSERT_ARRAY_NON_NULL(array, NULL);
     115    PS_ASSERT_ARRAY_NON_EMPTY(array, NULL);
     116
     117    int xMin = INT_MAX, xMax = INT_MIN, yMin = INT_MAX, yMax = INT_MIN; // Range for covariance
     118    int num = 0;                        // Number of good matrices to average
     119    for (int i = 0; i < array->n; i++) {
     120        psKernel *covar = array->data[i]; // Covariance matrix
     121        if (!covar) {
     122            continue;
     123        }
     124        xMin = PS_MIN(xMin, covar->xMin);
     125        xMax = PS_MAX(xMax, covar->xMax);
     126        yMin = PS_MIN(yMin, covar->yMin);
     127        yMax = PS_MIN(yMax, covar->yMax);
     128        num++;
     129    }
     130    if (num == 0) {
     131        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "No covariance matrices supplied for averaging.");
     132        return NULL;
     133    }
     134
     135    psKernel *average = psKernelAlloc(xMin, xMax, yMin, yMax); // Average covariance
     136    for (int i = 0; i < array->n; i++) {
     137        psKernel *covar = array->data[i]; // Covariance matrix
     138        if (!covar) {
     139            continue;
     140        }
     141        for (int y = yMin; y <= yMax; y++) {
     142            for (int x = xMin; x <= xMax; x++) {
     143                average->kernel[y][x] += covar->kernel[y][x];
     144            }
     145        }
     146    }
     147    psBinaryOp(average->image, average->image, "/", psScalarAlloc(num, PS_TYPE_F32));
     148
     149    return average;
     150}
Note: See TracChangeset for help on using the changeset viewer.