Changeset 14709 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Aug 30, 2007, 11:45:26 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r14701 r14709 4 4 * @author GLG, MHPCC 5 5 * 6 * @version $Revision: 1. 49$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-08-30 03:50:28$6 * @version $Revision: 1.50 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-08-30 21:45:26 $ 8 8 * 9 9 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 249 249 } 250 250 251 // Generate the convolution given a precalculated kernel252 static psKernel *convolvePrecalc(const psKernel *image, // Image to convolve (a kernel for convenience)253 const psKernel *kernel, // Kernel by which to convolve254 int footprint // Size of region of interest255 )256 {257 psImage *conv = psImageConvolveFFT(image->image, kernel, 0.0); // Convolved image258 int x0 = - image->xMin, y0 = - image->yMin; // Position of centre of convolved image259 psKernel *convolved = psKernelAllocFromImage(conv, x0, y0); // Kernel version260 psFree(conv);261 return convolved;262 }263 264 251 // Generate the convolved reference image 265 252 static psKernel *convolveRef(const pmSubtractionKernels *kernels, // Kernel basis functions … … 308 295 if (index < kernels->inner) { 309 296 // Photometric scaling is already built in to the precalculated kernel 310 return convolvePrecalc(image, kernels->preCalc->data[index], footprint);297 return p_pmSubtractionConvolveStampPrecalc(image, kernels->preCalc->data[index]); 311 298 } 312 299 // Using delta function … … 321 308 case PM_SUBTRACTION_KERNEL_ISIS: { 322 309 // Photometric scaling is already built in to the precalculated kernel 323 return convolvePrecalc(image, kernels->preCalc->data[index], footprint);310 return p_pmSubtractionConvolveStampPrecalc(image, kernels->preCalc->data[index]); 324 311 } 325 312 case PM_SUBTRACTION_KERNEL_RINGS: { … … 355 342 } 356 343 344 // Convolve an image using FFT 345 static void convolveFFT(psImage *target,// Place the result in here 346 const psImage *image, // Image to convolve 347 const psKernel *kernel, // Kernel by which to convolve 348 psRegion region,// Region of interest 349 float background, // Background to add 350 int size // Size of (square) kernel 351 ) 352 { 353 psRegion border = psRegionSet(region.x0 - size, region.x1 + size, 354 region.y0 - size, region.y1 + size); // Add a border 355 356 // Casting away const so psImageSubset can add the child 357 psImage *subImage = psImageSubset((psImage*)image, border); // Subimage to convolve 358 psImage *convolved = psImageConvolveFFT(subImage, kernel, 0.0); // Convolution 359 psFree(subImage); 360 361 // Now, we have to chop off the borders, and stick it in where it belongs 362 psImage *subConv = psImageSubset(convolved, psRegionSet(size, -size, 363 size, -size)); // Cut off the edges 364 psImage *subTarget = psImageSubset(target, region); // Target for this subregion 365 if (background != 0.0) { 366 psBinaryOp(subTarget, subConv, "+", psScalarAlloc(background, PS_TYPE_F32)); 367 } else { 368 int numBytes = subTarget->numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy 369 for (int y = 0; y < subTarget->numRows; y++) { 370 memcpy(subTarget->data.F32[y], subConv->data.F32[y], numBytes); 371 } 372 } 373 psFree(subConv); 374 psFree(convolved); 375 psFree(subTarget); 376 return; 377 } 378 379 // Convolve an image directly 380 static void convolveDirect(psImage *target, // Put the result here 381 const psImage *image, // Image to convolve 382 const psKernel *kernel, // Kernel by which to convolve 383 psRegion region,// Region of interest 384 float background, // Background to add 385 int size // Size of (square) kernel 386 ) 387 { 388 for (int y = region.y0; y < region.y1; y++) { 389 for (int x = region.x0; x < region.x1; x++) { 390 target->data.F32[y][x] = background; 391 for (int v = -size; v <= size; v++) { 392 for (int u = -size; u <= size; u++) { 393 target->data.F32[y][x] += kernel->kernel[v][u] * 394 image->data.F32[y - v][x - u]; 395 } 396 } 397 } 398 } 399 return; 400 } 401 357 402 // Mark a pixel as blank in the image, mask and weight 358 403 static inline void markBlank(psImage *image, // Image to mark as blank … … 372 417 return; 373 418 } 419 420 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 421 // Semi-public functions 422 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 423 424 // Generate the convolution given a precalculated kernel 425 psKernel *p_pmSubtractionConvolveStampPrecalc(const psKernel *image, const psKernel *kernel) 426 { 427 PS_ASSERT_KERNEL_NON_NULL(image, NULL); 428 PS_ASSERT_KERNEL_NON_NULL(kernel, NULL); 429 430 psImage *conv = psImageConvolveFFT(image->image, kernel, 0.0); // Convolved image 431 int x0 = - image->xMin, y0 = - image->yMin; // Position of centre of convolved image 432 psKernel *convolved = psKernelAllocFromImage(conv, x0, y0); // Kernel version 433 psFree(conv); 434 return convolved; 435 } 436 374 437 375 438 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 916 979 } 917 980 918 // Convolve an image using FFT919 static void convolveFFT(psImage *target,// Place the result in here920 const psImage *image, // Image to convolve921 const psKernel *kernel, // Kernel by which to convolve922 psRegion region,// Region of interest923 float background, // Background to add924 int size // Size of (square) kernel925 )926 {927 psRegion border = psRegionSet(region.x0 - size, region.x1 + size,928 region.y0 - size, region.y1 + size); // Add a border929 930 // Casting away const so psImageSubset can add the child931 psImage *subImage = psImageSubset((psImage*)image, border); // Subimage to convolve932 psImage *convolved = psImageConvolveFFT(subImage, kernel, 0.0); // Convolution933 psFree(subImage);934 935 // Now, we have to chop off the borders, and stick it in where it belongs936 psImage *subConv = psImageSubset(convolved, psRegionSet(size, -size,937 size, -size)); // Cut off the edges938 psImage *subTarget = psImageSubset(target, region); // Target for this subregion939 if (background != 0.0) {940 psBinaryOp(subTarget, subConv, "+", psScalarAlloc(background, PS_TYPE_F32));941 } else {942 int numBytes = subTarget->numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy943 for (int y = 0; y < subTarget->numRows; y++) {944 memcpy(subTarget->data.F32[y], subConv->data.F32[y], numBytes);945 }946 }947 psFree(subConv);948 psFree(convolved);949 psFree(subTarget);950 return;951 }952 953 // Convolve an image directly954 static void convolveDirect(psImage *target, // Put the result here955 const psImage *image, // Image to convolve956 const psKernel *kernel, // Kernel by which to convolve957 psRegion region,// Region of interest958 float background, // Background to add959 int size // Size of (square) kernel960 )961 {962 for (int y = region.y0; y < region.y1; y++) {963 for (int x = region.x0; x < region.x1; x++) {964 target->data.F32[y][x] = background;965 for (int v = -size; v <= size; v++) {966 for (int u = -size; u <= size; u++) {967 target->data.F32[y][x] += kernel->kernel[v][u] *968 image->data.F32[y - v][x - u];969 }970 }971 }972 }973 return;974 }975 976 981 bool pmSubtractionConvolve(psImage **outImage, psImage **outWeight, psImage **outMask, 977 982 const psImage *inImage, const psImage *inWeight, const psImage *subMask,
Note:
See TracChangeset
for help on using the changeset viewer.
