- Timestamp:
- Jan 28, 2009, 2:33:51 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_20090128/psModules/src/imcombine/pmSubtraction.c
r21183 r21211 60 60 61 61 // Normalise so that the sum of the variance kernel is the square of the sum of the normal kernel 62 // This is required to keep the relative scaling between the image and the weightmap62 // This is required to keep the relative scaling between the image and the variance map 63 63 psBinaryOp(out->image, out->image, "*", psScalarAlloc(PS_SQR(sumNormal) / sumVariance, PS_TYPE_F32)); 64 64 … … 287 287 288 288 // Convolve an image using FFT 289 static void convolve WeightFFT(psImage *target,// Place the result in here290 psImage * weight, // Weightmap to convolve289 static void convolveVarianceFFT(psImage *target,// Place the result in here 290 psImage *variance, // Variance map to convolve 291 291 psImage *sys, // Systematic error image 292 292 psImage *mask, // Mask image … … 302 302 bool threaded = pmSubtractionThreaded(); // Are we running threaded? 303 303 304 psImage *sub Weight = convolveSubsetAlloc(weight, border, threaded); // Weightmap304 psImage *subVariance = convolveSubsetAlloc(variance, border, threaded); // Variance map 305 305 psImage *subSys = convolveSubsetAlloc(sys, border, threaded); // Systematic error image 306 306 psImage *subMask = convolveSubsetAlloc(mask, border, threaded); // Mask 307 307 308 308 // XXX Can trim this a little by combining the convolution: only have to take the FFT of the kernel once 309 psImage *conv Weight = psImageConvolveFFT(NULL, subWeight, subMask, maskVal, kernel); // Convolved weight309 psImage *convVariance = psImageConvolveFFT(NULL, subVariance, subMask, maskVal, kernel); // Convolved variance 310 310 psImage *convSys = subSys ? psImageConvolveFFT(NULL, subSys, subMask, maskVal, kernel) : NULL; // Conv sys 311 311 312 convolveSubsetFree( weight, subWeight, threaded);312 convolveSubsetFree(variance, subVariance, threaded); 313 313 convolveSubsetFree(sys, subSys, threaded); 314 314 convolveSubsetFree(mask, subMask, threaded); … … 319 319 for (int yTarget = yMin, ySource = size; yTarget < yMax; yTarget++, ySource++) { 320 320 for (int xTarget = xMin, xSource = size; xTarget < xMax; xTarget++, xSource++) { 321 target->data.F32[yTarget][xTarget] = conv Weight->data.F32[ySource][xSource] +321 target->data.F32[yTarget][xTarget] = convVariance->data.F32[ySource][xSource] + 322 322 convSys->data.F32[ySource][xSource]; 323 323 } … … 326 326 int numBytes = (xMax - xMin) * PSELEMTYPE_SIZEOF(PS_TYPE_F32); // Number of bytes to copy 327 327 for (int yTarget = yMin, ySource = size; yTarget < yMax; yTarget++, ySource++) { 328 memcpy(&target->data.F32[yTarget][xMin], &conv Weight->data.F32[ySource][size], numBytes);329 } 330 } 331 332 psFree(conv Weight);328 memcpy(&target->data.F32[yTarget][xMin], &convVariance->data.F32[ySource][size], numBytes); 329 } 330 } 331 332 psFree(convVariance); 333 333 psFree(convSys); 334 334 … … 361 361 // Convolve a region of an image 362 362 static inline void convolveRegion(psImage *convImage, // Convolved image (output) 363 psImage *conv Weight, // Convolved weightmap (output), or NULL363 psImage *convVariance, // Convolved variance map (output), or NULL 364 364 psImage *convMask, // Convolve mask (output), or NULL 365 365 psKernel **kernelImage, // Convolution kernel for the image 366 psKernel **kernel Weight, // Convolution kernel for the weightmap, or NULL366 psKernel **kernelVariance, // Convolution kernel for the variance map, or NULL 367 367 psImage *image, // Image to convolve 368 psImage * weight, // Weightmap to convolve, or NULL368 psImage *variance, // Variance map to convolve, or NULL 369 369 psImage *sys, // Systematic error image, or NULL 370 370 psImage *subMask, // Subtraction mask … … 381 381 { 382 382 *kernelImage = solvedKernel(*kernelImage, kernels, polyValues, wantDual); 383 if ( weight|| subMask) {384 *kernel Weight = varianceKernel(*kernelWeight, *kernelImage);383 if (variance || subMask) { 384 *kernelVariance = varianceKernel(*kernelVariance, *kernelImage); 385 385 } 386 386 … … 398 398 } 399 399 400 // Convolve the image and weight400 // Convolve the image and variance 401 401 if (useFFT) { 402 402 // Use Fast Fourier Transform to do the convolution 403 403 // This provides a big speed-up for large kernels 404 404 convolveFFT(convImage, image, subMask, subBad, *kernelImage, region, background, kernels->size); 405 if ( weight) {406 convolve WeightFFT(convWeight, weight, sys, subMask, subBad, *kernelWeight, region, kernels->size);405 if (variance) { 406 convolveVarianceFFT(convVariance, variance, sys, subMask, subBad, *kernelVariance, region, kernels->size); 407 407 } 408 408 } else { 409 409 // XXX Direct convolution doesn't account for bad pixels yet 410 410 convolveDirect(convImage, image, *kernelImage, region, background, kernels->size); 411 if ( weight) {412 convolveDirect(conv Weight, weight, *kernelWeight, region, 0.0, kernels->size);411 if (variance) { 412 convolveDirect(convVariance, variance, *kernelVariance, region, 0.0, kernels->size); 413 413 } 414 414 } … … 885 885 psFree(stamp->image1); 886 886 psFree(stamp->image2); 887 psFree(stamp-> weight);888 stamp->image1 = stamp->image2 = stamp-> weight= NULL;887 psFree(stamp->variance); 888 stamp->image1 = stamp->image2 = stamp->variance = NULL; 889 889 psFree(stamp->matrix1); 890 890 psFree(stamp->matrix2); … … 989 989 990 990 991 // XXX Put kernelImage, kernel Weightand polyValues on thread-dependent data991 // XXX Put kernelImage, kernelVariance and polyValues on thread-dependent data 992 992 static bool subtractionConvolvePatch(int numCols, int numRows, // Size of image 993 993 int x0, int y0, // Offsets for image … … 1010 1010 1011 1011 psKernel *kernelImage = NULL; // Kernel for the images 1012 psKernel *kernel Weight = NULL; // Kernel for the weightmaps1012 psKernel *kernelVariance = NULL; // Kernel for the variance maps 1013 1013 1014 1014 // Only generate polynomial values every kernel footprint, since we have already assumed … … 1020 1020 1021 1021 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1022 convolveRegion(out1->image, out1-> weight, convMask, &kernelImage, &kernelWeight,1023 ro1->image, ro1-> weight, sys1, subMask, kernels, polyValues, background, *region,1022 convolveRegion(out1->image, out1->variance, convMask, &kernelImage, &kernelVariance, 1023 ro1->image, ro1->variance, sys1, subMask, kernels, polyValues, background, *region, 1024 1024 maskBad, maskPoor, poorFrac, useFFT, false); 1025 1025 } 1026 1026 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1027 convolveRegion(out2->image, out2-> weight, convMask, &kernelImage, &kernelWeight,1028 ro2->image, ro2-> weight, sys2, subMask, kernels, polyValues, background, *region,1027 convolveRegion(out2->image, out2->variance, convMask, &kernelImage, &kernelVariance, 1028 ro2->image, ro2->variance, sys2, subMask, kernels, polyValues, background, *region, 1029 1029 maskBad, maskPoor, poorFrac, useFFT, kernels->mode == PM_SUBTRACTION_MODE_DUAL); 1030 1030 } 1031 1031 1032 1032 psFree(kernelImage); 1033 psFree(kernel Weight);1033 psFree(kernelVariance); 1034 1034 psFree(polyValues); 1035 1035 … … 1148 1148 } 1149 1149 } 1150 if (ro1-> weight) {1151 if (!out1-> weight) {1152 out1-> weight= psImageAlloc(numCols, numRows, PS_TYPE_F32);1150 if (ro1->variance) { 1151 if (!out1->variance) { 1152 out1->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 1153 1153 if (threaded) { 1154 psMutexInit(out1-> weight);1154 psMutexInit(out1->variance); 1155 1155 } 1156 1156 } 1157 psImageInit(out1-> weight, 0.0);1157 psImageInit(out1->variance, 0.0); 1158 1158 } 1159 1159 } … … 1165 1165 } 1166 1166 } 1167 if (ro2-> weight) {1168 if (!out2-> weight) {1169 out2-> weight= psImageAlloc(numCols, numRows, PS_TYPE_F32);1167 if (ro2->variance) { 1168 if (!out2->variance) { 1169 out2->variance = psImageAlloc(numCols, numRows, PS_TYPE_F32); 1170 1170 if (threaded) { 1171 psMutexInit(out2-> weight);1171 psMutexInit(out2->variance); 1172 1172 } 1173 1173 } 1174 psImageInit(out2-> weight, 0.0);1174 psImageInit(out2->variance, 0.0); 1175 1175 } 1176 1176 } … … 1232 1232 psImage *polyValues = NULL; // Pre-calculated polynomial values 1233 1233 psKernel *kernelImage = NULL; // Kernel for the images 1234 psKernel *kernel Weight = NULL; // Kernel for the weightmaps1234 psKernel *kernelVariance = NULL; // Kernel for the variance maps 1235 1235 #endif 1236 1236 … … 1345 1345 if (out2) { 1346 1346 out2->image = psMemIncrRefCounter(ro2->image); 1347 out2-> weight = psMemIncrRefCounter(ro2->weight);1347 out2->variance = psMemIncrRefCounter(ro2->variance); 1348 1348 out2->mask = psMemIncrRefCounter(ro2->mask); 1349 1349 } … … 1352 1352 if (out1) { 1353 1353 out1->image = psMemIncrRefCounter(ro1->image); 1354 out1-> weight = psMemIncrRefCounter(ro1->weight);1354 out1->variance = psMemIncrRefCounter(ro1->variance); 1355 1355 out1->mask = psMemIncrRefCounter(ro1->mask); 1356 1356 }
Note:
See TracChangeset
for help on using the changeset viewer.
