Changeset 21280
- Timestamp:
- Feb 3, 2009, 4:55:27 PM (17 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 4 edited
-
psImageCovariance.c (modified) (3 diffs)
-
psImageCovariance.h (modified) (3 diffs)
-
psImageInterpolate.c (modified) (3 diffs)
-
psImageInterpolate.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageCovariance.c
r21207 r21280 11 11 12 12 #include "psImageCovariance.h" 13 14 psKernel *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 } 13 20 14 21 … … 25 32 // where M^x is the covariance matrix for x. 26 33 // 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, which29 // makes storage difficult; and if that's not enough, the time to do the calculation is definitely30 // impractical). Since there are (generally) lots of zeros in the covariance matrix, and the same basic31 // 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) and33 // neighbouring pixels. Note that this may not be strictly correct near sources, but this is the best we34 // can do (and much better than most currently do).35 34 36 35 psKernel *covar; // Covariance matrix to use … … 108 107 float psImageCovarianceFactor(const psKernel *covariance) 109 108 { 110 return covariance ? covariance->kernel[0][0] : 1.0;109 return covariance ? covariance->kernel[0][0] : NAN; 111 110 } 112 111 112 psKernel *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 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2009-0 1-28 22:16:33$7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2009-02-04 02:55:27 $ 9 9 * Copyright 2009 Institute for Astronomy, University of Hawaii 10 10 */ … … 17 17 18 18 #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 29 psKernel *psImageCovarianceNone(void); 19 30 20 31 /// Calculate the covariance pseudo-matrix for a convolution kernel … … 29 40 ); 30 41 42 /// Average many covariance pseudo-matrices 43 psKernel *psImageCovarianceAverage( 44 const psArray *array ///< Array of covariance pseudo-matrices 45 ); 46 31 47 32 48 /// @} -
trunk/psLib/src/imageops/psImageInterpolate.c
r21183 r21280 7 7 * @author Paul Price, IfA 8 8 * 9 * @version $Revision: 1.3 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2009-0 1-27 06:39:37 $9 * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2009-02-04 02:55:27 $ 11 11 * 12 12 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 866 866 867 867 868 psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psImageMaskType *maskValue, 869 float x, float y, const psImageInterpolation *interp) 868 psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, 869 psImageMaskType *maskValue, float x, float y, 870 const psImageInterpolation *interp) 870 871 { 871 872 PS_ASSERT_PTR_NON_NULL(imageValue, PS_INTERPOLATE_STATUS_ERROR); … … 963 964 964 965 966 psKernel *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 965 991 psImageInterpolateMode psImageInterpolateModeFromString(const char *name) 966 992 { -
trunk/psLib/src/imageops/psImageInterpolate.h
r21183 r21280 7 7 * @author Paul Price, Institute for Astronomy 8 8 * 9 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $10 * @date $Date: 2009-0 1-27 06:39:37 $9 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2009-02-04 02:55:27 $ 11 11 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii 12 12 */ … … 50 50 const psImage *variance; ///< Variance image for interpolation 51 51 const psImage *mask; ///< Mask image for interpolation 52 psImageMaskType maskVal; ///< Value to mask52 psImageMaskType maskVal; ///< Value to mask 53 53 double badImage; ///< Image value if x,y location is not good 54 54 double badVariance; ///< Variance value if x,y location is not good 55 psImageMaskType badMask; ///< Mask value to give bad pixels56 psImageMaskType poorMask; ///< Mask value to give poor pixels55 psImageMaskType badMask; ///< Mask value to give bad pixels 56 psImageMaskType poorMask; ///< Mask value to give poor pixels 57 57 float poorFrac; ///< Fraction of flux in bad pixels before output is marked bad 58 58 bool shifting; ///< Shifting images? Don't interpolate if the shift is exact. … … 101 101 ); 102 102 103 /// Generate the appropriate interpolation kernel 104 psKernel *psImageInterpolationKernel(float x, float y, ///< Position of interest 105 psImageInterpolateMode mode ///< Interpolation mode 106 ); 107 103 108 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
