Changeset 12179
- Timestamp:
- Mar 2, 2007, 11:05:52 AM (19 years ago)
- Location:
- trunk/psLib
- Files:
-
- 3 edited
-
src/imageops/psImageConvolve.c (modified) (6 diffs)
-
src/imageops/psImageConvolve.h (modified) (3 diffs)
-
test/imageops/tap_psImageConvolve2.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r12001 r12179 7 7 /// @author Eugene Magnier, IfA 8 8 /// 9 /// @version $Revision: 1.4 7$ $Name: not supported by cvs2svn $10 /// @date $Date: 2007-0 2-22 22:37:59$9 /// @version $Revision: 1.48 $ $Name: not supported by cvs2svn $ 10 /// @date $Date: 2007-03-02 21:05:52 $ 11 11 /// 12 12 /// Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 195 195 } 196 196 197 psImage *psImageConvolveDirect(psImage *out, 198 const psImage *in, 197 psImage *psImageConvolveDirect(const psImage *in, 199 198 const psKernel *kernel) 200 199 { … … 214 213 int numCols = in->numCols; // Number of columns 215 214 215 psImage *out; // Image to be returned 216 217 #if 0 218 219 // This is the usual way of doing the convolution, but it wastes time if there's a large number of zero 220 // pixels in the kernel. 216 221 #define SPATIAL_CONVOLVE_CASE(TYPE) \ 217 222 case PS_TYPE_##TYPE: { \ 218 ps##TYPE **inData = in->data.TYPE; \219 out = psImage Recycle(out,numCols, numRows, PS_TYPE_##TYPE); \223 ps##TYPE **inData = in->data.TYPE; /* Dereference input data */ \ 224 out = psImageAlloc(numCols, numRows, PS_TYPE_##TYPE); \ 220 225 for (int row = 0; row < numRows; row++) { \ 221 226 ps##TYPE *outRow = out->data.TYPE[row]; \ … … 233 238 break; 234 239 240 #else 241 242 // This turns the convolution inside-out, allowing us to skip kernel pixels that have no contribution. 243 #define SPATIAL_CONVOLVE_CASE(TYPE) \ 244 case PS_TYPE_##TYPE: { \ 245 ps##TYPE **inData = in->data.TYPE; /* Dereference input data */ \ 246 out = psImageAlloc(numCols, numRows, PS_TYPE_##TYPE); \ 247 psImageInit(out, 0.0); \ 248 for (int ky = yMin; ky <= yMax; ky++) { \ 249 for (int kx = xMin; kx <= xMax; kx++) { \ 250 float kValue = kernelData[ky][kx]; /* Kernel value */ \ 251 if (kValue == 0.0) { \ 252 continue; \ 253 } \ 254 for (int y = PS_MAX(- ky, 0); y < PS_MIN(numRows, numRows - ky); y++) { \ 255 for (int x = PS_MAX(- kx, 0); x < PS_MIN(numCols, numCols - kx); x++) { \ 256 out->data.TYPE[y][x] += kValue * inData[y + ky][x + kx]; \ 257 } \ 258 } \ 259 } \ 260 } \ 261 } \ 262 break; 263 264 #endif 265 235 266 switch (in->type.type) { 236 267 SPATIAL_CONVOLVE_CASE(F32); … … 243 274 } 244 275 245 psImage *psImageConvolveFFT(psImage *out, 246 const psImage *in, 276 psImage *psImageMaskConvolve(const psImage *mask, psMaskType maskVal, const psKernel *kernel) 277 { 278 PS_ASSERT_IMAGE_NON_NULL(mask, NULL); 279 PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL); 280 PS_ASSERT_PTR_NON_NULL(kernel, NULL); 281 PS_ASSERT_PTR_NON_NULL(kernel->kernel, NULL); 282 283 // Pull out kernel parameters, for convenience 284 int xMin = kernel->xMin; 285 int xMax = kernel->xMax; 286 int yMin = kernel->yMin; 287 int yMax = kernel->yMax; 288 289 int numRows = mask->numRows; // Number of rows 290 int numCols = mask->numCols; // Number of columns 291 292 psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA; 293 psImage *out = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 294 psImageInit(out, 0); 295 296 for (int kRow = yMin; kRow <= yMax; kRow++) { 297 for (int kCol = xMin; kCol <= xMax; kCol++) { 298 psMaskType kValue = kernel->kernel[kRow][kCol]; // Value of the kernel 299 if (kValue == 0) { 300 continue; 301 } 302 for (int row = PS_MAX(kRow, 0); row < PS_MIN(numRows, numRows - kRow); row++) { 303 for (int col = PS_MAX(kCol, 0); col < PS_MIN(numCols, numCols - kCol); col++) { 304 if (maskData[row][col] & maskVal) { 305 out->data.PS_TYPE_MASK_DATA[row + kRow][col + kCol] = maskVal; 306 } 307 } 308 } 309 } 310 } 311 312 return out; 313 } 314 315 316 psImage *psImageConvolveFFT(const psImage *in, 247 317 const psKernel *kernel, 248 318 float pad) … … 356 426 // Trim off the padding, then renormalise (which also does a copy, so there's no parent for the output) 357 427 psImage *convolved = psImageSubset(paddedConvolved, psRegionSet(0, numCols, 0, numRows)); 358 out = (psImage*)psBinaryOp(out, convolved, "*",359 psScalarAlloc(1.0 / paddedCols / paddedRows, PS_TYPE_F32));428 psImage *out = (psImage*)psBinaryOp(NULL, convolved, "*", 429 psScalarAlloc(1.0 / paddedCols / paddedRows, PS_TYPE_F32)); 360 430 psFree(convolved); 361 431 psFree(paddedConvolved); -
trunk/psLib/src/imageops/psImageConvolve.h
r11703 r12179 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-0 2-08 04:17:58$7 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-03-02 21:05:52 $ 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 10 10 */ … … 112 112 /// 113 113 psImage *psImageConvolveDirect( 114 psImage *out, ///< a psImage to recycle. If NULL, a new psImage is made.115 114 const psImage *in, ///< the psImage to convolve 116 115 const psKernel *kernel ///< kernel to colvolve with … … 122 121 /// are suitably padded to avoid wrap-around effects. 123 122 psImage *psImageConvolveFFT( 124 psImage *out, ///< a psImage to recycle. If NULL, a new psImage is made.125 123 const psImage *in, ///< the psImage to convolve 126 124 const psKernel *kernel, ///< kernel to colvolve with -
trunk/psLib/test/imageops/tap_psImageConvolve2.c
r11725 r12179 71 71 psKernel *kernel = generateKernel(); 72 72 73 psImage *convolved = psImageConvolveDirect( NULL,image, kernel);73 psImage *convolved = psImageConvolveDirect(image, kernel); 74 74 ok(convolved, "convolution result"); 75 75 skip_start(!convolved, 3, "convolution failed"); … … 94 94 psKernel *kernel = generateKernel(); 95 95 96 psImage *convolved = psImageConvolveFFT( NULL,image, kernel, 0.0);96 psImage *convolved = psImageConvolveFFT(image, kernel, 0.0); 97 97 ok(convolved, "convolution result"); 98 98 skip_start(!convolved, 3, "convolution failed");
Note:
See TracChangeset
for help on using the changeset viewer.
