Changeset 28667 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Jul 13, 2010, 2:34:04 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r28405 r28667 52 52 53 53 // Take the square of the normal kernel 54 double sumVariance = 0.0; // Sum of the variance kernels55 54 for (int v = yMin; v <= yMax; v++) { 56 55 for (int u = xMin; u <= xMax; u++) { 57 sumVariance += out->kernel[v][u] = PS_SQR(normalKernel->kernel[v][u]); 58 } 59 } 60 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 variance map 63 psBinaryOp(out->image, out->image, "*", psScalarAlloc(1.0 / sumVariance, PS_TYPE_F32)); 64 56 out->kernel[v][u] = PS_SQR(normalKernel->kernel[v][u]); 57 } 58 } 65 59 return out; 66 60 } … … 271 265 // Convolve an image using FFT 272 266 static void convolveVarianceFFT(psImage *target,// Place the result in here 273 psImage *variance, // Variance map to convolve274 psImage *kernelErr, // Kernel error image275 psImage *mask, // Mask image276 psImageMaskType maskVal, // Value to mask277 const psKernel *kernel, // Kernel by which to convolve278 psRegion region,// Region of interest279 int size // Size of (square) kernel280 )267 psImage *variance, // Variance map to convolve 268 psImage *kernelErr, // Kernel error image 269 psImage *mask, // Mask image 270 psImageMaskType maskVal, // Value to mask 271 const psKernel *kernel, // Kernel by which to convolve 272 psRegion region,// Region of interest 273 int size // Size of (square) kernel 274 ) 281 275 { 282 276 psRegion border = psRegionSet(region.x0 - size, region.x1 + size, … … 348 342 psImage *image, // Image to convolve 349 343 psImage *variance, // Variance map to convolve, or NULL 344 const psKernel *covar, // Covariance, or NULL 350 345 psImage *kernelErr, // Kernel error image, or NULL 351 346 psImage *subMask, // Subtraction mask … … 393 388 if (variance) { 394 389 convolveDirect(convVariance, variance, *kernelVariance, region, 0.0, kernels->size); 390 } 391 } 392 393 if (variance && covar) { 394 // Apply covariance factor to variance map, to allow for spatial variation 395 float factor = psImageCovarianceCalculateFactor(*kernelImage, covar); // Factor to apply 396 for (int y = region.y0; y < region.y1; y++) { 397 for (int x = region.x0; x < region.x1; x++) { 398 convVariance->data.F32[y][x] *= factor; 399 } 395 400 } 396 401 } … … 1085 1090 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1086 1091 convolveRegion(out1->image, out1->variance, out1->mask, &kernelImage, &kernelVariance, 1087 ro1->image, ro1->variance, kernelErr1, subMask, kernels, polyValues, background,1088 *region, maskBad, maskPoor, poorFrac, useFFT, false);1092 ro1->image, ro1->variance, ro1->covariance, kernelErr1, subMask, kernels, 1093 polyValues, background, *region, maskBad, maskPoor, poorFrac, useFFT, false); 1089 1094 } 1090 1095 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { 1091 1096 convolveRegion(out2->image, out2->variance, out2->mask, &kernelImage, &kernelVariance, 1092 ro2->image, ro2->variance, kernelErr2, subMask, kernels, polyValues, background,1093 *region, maskBad, maskPoor, poorFrac, useFFT,1097 ro2->image, ro2->variance, ro2->covariance, kernelErr2, subMask, kernels, 1098 polyValues, background, *region, maskBad, maskPoor, poorFrac, useFFT, 1094 1099 kernels->mode == PM_SUBTRACTION_MODE_DUAL); 1095 1100 } … … 1325 1330 1326 1331 // Calculate covariances 1327 // This can be fairly involved, so we only do it for a single instance 1328 // Enable threads for covariance calculation, since we're not threading on top of it. 1332 // This can be fairly involved, so we only do it for a small number of instances 1329 1333 float position[NUM_COVAR_POS] = { -1.0, -0.5, 0.0, +0.5, +1.0 }; // Positions for covariance calculations 1334 // Enable threads for covariance calculation, since we're not threading on top of it 1330 1335 oldThreads = psImageCovarianceSetThreads(true); 1331 1336 if (kernels->mode == PM_SUBTRACTION_MODE_1 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { … … 1342 1347 out1->covariance = psImageCovarianceAverage(covars); 1343 1348 psFree(covars); 1349 // Remove covariance factor from covariance, since we've put it in the variance map already 1350 float factor = psImageCovarianceFactor(out1->covariance); 1351 psBinaryOp(out1->covariance->image, out1->covariance->image, "/", psScalarAlloc(factor, PS_TYPE_F32)); 1344 1352 } 1345 1353 if (kernels->mode == PM_SUBTRACTION_MODE_2 || kernels->mode == PM_SUBTRACTION_MODE_DUAL) { … … 1356 1364 out2->covariance = psImageCovarianceAverage(covars); 1357 1365 psFree(covars); 1366 // Remove covariance factor from covariance, since we've put it in the variance map already 1367 float factor = psImageCovarianceFactor(out2->covariance); 1368 psBinaryOp(out2->covariance->image, out2->covariance->image, "/", psScalarAlloc(factor, PS_TYPE_F32)); 1358 1369 } 1359 1370 psImageCovarianceSetThreads(oldThreads);
Note:
See TracChangeset
for help on using the changeset viewer.
