Changeset 21280 for trunk/psLib/src/imageops/psImageCovariance.c
- Timestamp:
- Feb 3, 2009, 4:55:27 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageCovariance.c (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 }
Note:
See TracChangeset
for help on using the changeset viewer.
