IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21280


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.

Location:
trunk/psLib/src/imageops
Files:
4 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}
  • trunk/psLib/src/imageops/psImageCovariance.h

    r21207 r21280  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2009-01-28 22:16:33 $
     7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2009-02-04 02:55:27 $
    99 * Copyright 2009 Institute for Astronomy, University of Hawaii
    1010 */
     
    1717
    1818#include <psImageConvolve.h>
     19
     20// We don't carry the entire covariance matrix for an image (the size goes as N^2, for N pixels, which makes
     21// storage difficult; and if that's not enough, the time to do the calculation is definitely impractical).
     22// Since there are (generally) lots of zeros in the covariance matrix, and the same basic pattern repeats (for
     23// background pixels), we can just carry that pattern.  We carry this in a psKernel, since the values are the
     24// covariance between the pixel of consideration (at 0,0 in the kernel) and neighbouring pixels.  Note that
     25// this may not be strictly correct near sources, but this is the best we can do (and much better than most
     26// currently do).
     27
     28/// Allocate a covariance pseudo-matrix with no covariance
     29psKernel *psImageCovarianceNone(void);
    1930
    2031/// Calculate the covariance pseudo-matrix for a convolution kernel
     
    2940    );
    3041
     42/// Average many covariance pseudo-matrices
     43psKernel *psImageCovarianceAverage(
     44    const psArray *array                ///< Array of covariance pseudo-matrices
     45    );
     46
    3147
    3248/// @}
  • trunk/psLib/src/imageops/psImageInterpolate.c

    r21183 r21280  
    77 *  @author Paul Price, IfA
    88 *
    9  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2009-01-27 06:39:37 $
     9 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2009-02-04 02:55:27 $
    1111 *
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    866866
    867867
    868 psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psImageMaskType *maskValue,
    869                                             float x, float y, const psImageInterpolation *interp)
     868psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue,
     869                                            psImageMaskType *maskValue, float x, float y,
     870                                            const psImageInterpolation *interp)
    870871{
    871872    PS_ASSERT_PTR_NON_NULL(imageValue, PS_INTERPOLATE_STATUS_ERROR);
     
    963964
    964965
     966psKernel *psImageInterpolationKernel(float x, float y, psImageInterpolateMode mode)
     967{
     968    int size = kernelSizes[mode];       // Size of kernel
     969
     970    // Kernel basics
     971    INTERPOLATE_SETUP(x, y);
     972    xExact = yExact = false;
     973
     974    psF32 xKernel[size], yKernel[size]; // Interpolation kernels
     975    interpolationKernel(xKernel, xFrac, mode);
     976    interpolationKernel(yKernel, yFrac, mode);
     977
     978    int min = -size/2, max = (size - 1) / 2; // Range for kernel
     979    psKernel *kernel = psKernelAlloc(min, max, min, max); // Kernel to return
     980
     981    for (int y = 0; y < size; y++) {
     982        for (int x = 0; x < size; x++) {
     983            kernel->kernel[y][x] = yKernel[y] * xKernel[x];
     984        }
     985    }
     986
     987    return kernel;
     988}
     989
     990
    965991psImageInterpolateMode psImageInterpolateModeFromString(const char *name)
    966992{
  • trunk/psLib/src/imageops/psImageInterpolate.h

    r21183 r21280  
    77 * @author Paul Price, Institute for Astronomy
    88 *
    9  * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    10  * @date $Date: 2009-01-27 06:39:37 $
     9 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     10 * @date $Date: 2009-02-04 02:55:27 $
    1111 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii
    1212 */
     
    5050    const psImage *variance;            ///< Variance image for interpolation
    5151    const psImage *mask;                ///< Mask image for interpolation
    52     psImageMaskType maskVal;            ///< Value to mask
     52    psImageMaskType maskVal;            ///< Value to mask
    5353    double badImage;                    ///< Image value if x,y location is not good
    5454    double badVariance;                 ///< Variance value if x,y location is not good
    55     psImageMaskType badMask;            ///< Mask value to give bad pixels
    56     psImageMaskType poorMask;           ///< Mask value to give poor pixels
     55    psImageMaskType badMask;            ///< Mask value to give bad pixels
     56    psImageMaskType poorMask;           ///< Mask value to give poor pixels
    5757    float poorFrac;                     ///< Fraction of flux in bad pixels before output is marked bad
    5858    bool shifting;                      ///< Shifting images? Don't interpolate if the shift is exact.
     
    101101    );
    102102
     103/// Generate the appropriate interpolation kernel
     104psKernel *psImageInterpolationKernel(float x, float y, ///< Position of interest
     105                                     psImageInterpolateMode mode ///< Interpolation mode
     106    );
     107
    103108#endif
Note: See TracChangeset for help on using the changeset viewer.