Changeset 21316
- Timestamp:
- Feb 5, 2009, 10:15:32 AM (17 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 2 edited
-
psImageCovariance.c (modified) (2 diffs)
-
psImageCovariance.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageCovariance.c
r21298 r21316 5 5 #include <stdio.h> 6 6 #include <limits.h> 7 #include <string.h> 7 8 8 9 #include "psMemory.h" … … 172 173 return sum; 173 174 } 175 176 177 psKernel *psImageCovarianceTruncate(const psKernel *covar, float frac) 178 { 179 PS_ASSERT_KERNEL_NON_NULL(covar, NULL); 180 PS_ASSERT_FLOAT_WITHIN_RANGE(frac, 0, 1, NULL); 181 182 int xMin = covar->xMin, xMax = covar->xMax, yMin = covar->yMin, yMax = covar->yMax; // Range 183 184 double sum = 0.0; // Sum of covariance 185 for (int y = yMin; y <= yMax; y++) { 186 for (int x = xMin; x <= xMax; x++) { 187 sum += covar->kernel[y][x]; 188 } 189 } 190 191 // Determine radius for truncation 192 double threshold = (1.0 - frac) * sum; // Threshold for truncation 193 int maxRadius = PS_MAX(PS_MAX(PS_MAX(xMax, yMax), -xMin), yMin); // Maximum radius of covariance matrix 194 double enclosed = NAN; // Enclosed value 195 int radius; // Radius at which to truncate 196 for (radius = 0; radius <= maxRadius && enclosed < threshold; radius++) { 197 // Not so efficient to execute, but easy to code; it should be fast anyway 198 enclosed = 0.0; 199 for (int y = PS_MAX(yMin, -radius); y <= PS_MIN(yMax, radius); y++) { 200 for (int x = PS_MAX(xMin, -radius); x <= PS_MIN(xMax, radius); x++) { 201 enclosed += covar->kernel[y][x]; 202 } 203 } 204 } 205 206 // Generate truncated version 207 psKernel *trunc = psKernelAlloc(-radius, radius, -radius, radius); // Truncated covariance matrix 208 int numBytes = (2 * radius + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy 209 for (int y = -radius; y <= radius; y++) { 210 memcpy(trunc->kernel[y], covar->kernel[y], numBytes); 211 } 212 213 return trunc; 214 } -
trunk/psLib/src/imageops/psImageCovariance.h
r21298 r21316 5 5 * @author Paul Price, IfA 6 6 * 7 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2009-02-05 00:42:48$7 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2009-02-05 20:15:32 $ 9 9 * Copyright 2009 Institute for Astronomy, University of Hawaii 10 10 */ … … 21 21 // storage difficult; and if that's not enough, the time to do the calculation is definitely impractical). 22 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 the24 // covariance between the pixel of consideration (at 0,0 in the kernel) and neighbouring pixels. Note that25 // this may not be strictly correct near sources, but this is the best we can do (and much better than most26 // currently do).23 // background pixels), we can just carry that pattern ("covariance pseudo-matrix"). We carry this in a 24 // psKernel, since the values are the covariance between the pixel of consideration (at 0,0 in the kernel) and 25 // neighbouring pixels. Note that this may not be strictly correct near sources, but this is the best we can 26 // do (and much better than most currently do). 27 27 28 28 /// Allocate a covariance pseudo-matrix with no covariance … … 50 50 ); 51 51 52 /// Truncate covariance pseudo-matrix 53 /// 54 /// The covariance pseudo-matrix is truncated by removing the outer regions that contribute less than the 55 /// nominated fraction of the total. 56 psKernel *psImageCovarianceTruncate( 57 const psKernel *covar, ///< Covariance pseudo-matrix 58 float frac ///< Fraction of covariance to truncate 59 ); 52 60 53 61 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
