Changeset 24298 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Jun 2, 2009, 10:10:32 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r23989 r24298 196 196 { 197 197 psKernel *convolved = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Convolved image 198 int numBytes = (2 * footprint + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy199 198 for (int y = -footprint; y <= footprint; y++) { 200 // Convolution with a delta function is just the value specified by the offset 201 memcpy(&convolved->kernel[y][-footprint], &image->kernel[y - v][-footprint - u], numBytes); 199 for (int x = -footprint; x <= footprint; x++) { 200 convolved->kernel[y][x] = image->kernel[y - v][x - u]; 201 } 202 202 } 203 203 return convolved; 204 204 } 205 205 206 // Take a subset of an image207 static inline psImage *convolveSubsetAlloc(psImage *image, // Image to be convolved208 psRegion region, // Region of interest (with border)209 bool threaded // Are we running threaded?210 )211 {212 if (!image) {213 return NULL;214 }215 // XXX if (threaded) {216 // XXX psMutexLock(image);217 // XXX }218 psImage *subset = psImageSubset(image, region); // Subset image, to return219 // XXX if (threaded) {220 // XXX psMutexUnlock(image);221 // XXX }222 return subset;223 }224 225 // Free the subset of an image226 static inline void convolveSubsetFree(psImage *parent, // Parent image227 psImage *child, // Child (subset) image228 bool threaded // Are we running threaded?229 )230 {231 if (!child || !parent) {232 return;233 }234 // XXX if (threaded) {235 // XXX psMutexLock(parent);236 // XXX }237 psFree(child);238 // XXX if (threaded) {239 // XXX psMutexUnlock(parent);240 // XXX }241 return;242 }243 206 244 207 // Convolve an image using FFT … … 256 219 region.y0 - size, region.y1 + size); // Add a border 257 220 258 bool threaded = pmSubtractionThreaded(); // Are we running threaded? 259 260 psImage *subImage = convolveSubsetAlloc(image, border, threaded); // Subimage to convolve 261 psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Subimage mask 221 psImage *subImage = image ? psImageSubset(image, border) : NULL; // Subimage to convolve 222 psImage *subMask = mask ? psImageSubset(mask, border) : NULL; // Subimage mask 262 223 263 224 psImage *convolved = psImageConvolveFFT(NULL, subImage, subMask, maskVal, kernel); // Convolution 264 225 265 convolveSubsetFree(image, subImage, threaded);266 convolveSubsetFree(mask, subMask, threaded);226 psFree(subImage); 227 psFree(subMask); 267 228 268 229 // Now, we have to stick it in where it belongs … … 300 261 region.y0 - size, region.y1 + size); // Add a border 301 262 302 bool threaded = pmSubtractionThreaded(); // Are we running threaded? 303 304 psImage *subVariance = convolveSubsetAlloc(variance, border, threaded); // Variance map 305 psImage *subSys = convolveSubsetAlloc(sys, border, threaded); // Systematic error image 306 psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Mask 263 psImage *subVariance = variance ? psImageSubset(variance, border) : NULL; // Variance map 264 psImage *subSys = sys ? psImageSubset(sys, border) : NULL; // Systematic error image 265 psImage *subMask = mask ? psImageSubset(mask, border) : NULL; // Mask 307 266 308 267 // XXX Can trim this a little by combining the convolution: only have to take the FFT of the kernel once … … 310 269 psImage *convSys = subSys ? psImageConvolveFFT(NULL, subSys, subMask, maskVal, kernel) : NULL; // Conv sys 311 270 312 convolveSubsetFree(variance, subVariance, threaded);313 convolveSubsetFree(sys, subSys, threaded);314 convolveSubsetFree(mask, subMask, threaded);271 psFree(subVariance); 272 psFree(subSys); 273 psFree(subMask); 315 274 316 275 // Now, we have to stick it in where it belongs … … 420 379 if (box > 0) { 421 380 int colMin = region.x0, colMax = region.x1, rowMin = region.y0, rowMax = region.y1; // Bounds 422 bool threaded = pmSubtractionThreaded(); // Are we running threaded?423 424 381 psRegion region = psRegionSet(colMin - box, colMax + box, 425 382 rowMin - box, rowMax + box); // Region to convolve 426 383 427 psImage *image = convolveSubsetAlloc(subMask, region, threaded); // Mask to convolve384 psImage *image = subMask ? psImageSubset(subMask, region) : NULL; // Mask to convolve 428 385 429 386 psImage *convolved = psImageConvolveMask(NULL, image, subBad, subConvBad, 430 387 -box, box, -box, box); // Convolved subtraction mask 431 388 432 convolveSubsetFree(subMask, image, threaded);389 psFree(image); 433 390 434 391 psAssert(convolved->numCols - 2 * box == colMax - colMin, "Bad number of columns"); … … 653 610 float value = 0.0; // Value of convolved pixel 654 611 int uMin = x - size, uMax = x + size; // Range for u 655 psF32 *xKernelData = xKernel->data.F32; // Kernel values612 psF32 *xKernelData = &xKernel->data.F32[xKernel->n - 1]; // Kernel values 656 613 psF32 *imageData = &image->kernel[y][uMin]; // Image values 657 for (int u = uMin; u <= uMax; u++, xKernelData ++, imageData++) {614 for (int u = uMin; u <= uMax; u++, xKernelData--, imageData++) { 658 615 value += *xKernelData * *imageData; 659 616 } … … 668 625 float value = 0.0; // Value of convolved pixel 669 626 int vMin = y - size, vMax = y + size; // Range for v 670 psF32 *yKernelData = yKernel->data.F32; // Kernel values627 psF32 *yKernelData = &yKernel->data.F32[yKernel->n - 1]; // Kernel values 671 628 psF32 *imageData = &temp->kernel[x][vMin]; // Image values; NOTE: wrong way! 672 for (int v = vMin; v <= vMax; v++, yKernelData ++, imageData++) {629 for (int v = vMin; v <= vMax; v++, yKernelData--, imageData++) { 673 630 value += *yKernelData * *imageData; 674 631 }
Note:
See TracChangeset
for help on using the changeset viewer.
