Changeset 19282 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Aug 28, 2008, 6:04:19 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r19271 r19282 300 300 psImage *subMask, // Subtraction mask 301 301 const pmSubtractionKernels *kernels, // Kernels 302 psImage *polyValues, // Polynomial values302 const psImage *polyValues, // Polynomial values 303 303 float background, // Background value to apply 304 304 psRegion region, // Region to convolve … … 340 340 // Convolve the mask for bad pixels 341 341 if (subMask && convMask) { 342 psKernel *kernel = *kernelWeight; // Kernel of interest 343 int xMin = kernel->xMin, xMax = kernel->xMax, yMin = kernel->yMin, yMax = kernel->yMax; // Bounds 344 345 // Determine the thresholds 346 double sumKernel2 = 0.0; // Sum of the kernel-squared 347 for (int y = yMin; y <= yMax; y++) { 348 for (int x = xMin; x <= xMax; x++) { 349 sumKernel2 += kernel->kernel[y][x]; 350 } 351 } 352 float threshold = sumKernel2 * poorFrac; // Threshold between poor and bad 353 354 // Get bounds of threshold region 355 // Start with the entire kernel, and keep reducing the size of the box until it drops below threshold 356 int box = kernels->size; // Size of box with bad pixels 357 for (double sumBox = sumKernel2; box > 0; box--) { 358 for (int x = -box; x <= box; x++) { 359 sumBox -= kernel->kernel[-box][x] + kernel->kernel[box][x]; 360 } 361 for (int y = -box + 1; y <= box - 1; y++) { 362 // Note: not doing corners 363 sumBox -= kernel->kernel[y][-box] + kernel->kernel[y][box]; 364 } 365 if (sumBox < threshold) { 366 break; 367 } 368 } 369 342 int box = p_pmSubtractionBadRadius(*kernelImage, kernels, polyValues, 343 wantDual, poorFrac); // Size of bad box 370 344 if (box > 0) { 371 345 int colMin = region.x0, colMax = region.x1, rowMin = region.y0, rowMax = region.y1; // Bounds … … 415 389 return; 416 390 } 391 392 417 393 418 394 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 430 406 psFree(conv); 431 407 return convolved; 408 } 409 410 int p_pmSubtractionBadRadius(psKernel *preKernel, const pmSubtractionKernels *kernels, 411 const psImage *polyValues, bool wantDual, float poorFrac) 412 { 413 psKernel *kernel; // Kernel to use 414 if (!preKernel) { 415 kernel = solvedKernel(NULL, kernels, polyValues, wantDual); 416 } else { 417 kernel = psMemIncrRefCounter(preKernel); 418 } 419 PS_ASSERT_IMAGE_NON_NULL(polyValues, -1); 420 421 int xMin = kernel->xMin, xMax = kernel->xMax, yMin = kernel->yMin, yMax = kernel->yMax; // Bounds 422 423 // Determine the threshold between bad and poor 424 double sumKernel2 = 0.0; // Sum of the kernel-squared 425 for (int y = yMin; y <= yMax; y++) { 426 for (int x = xMin; x <= xMax; x++) { 427 sumKernel2 += PS_SQR(kernel->kernel[y][x]); 428 } 429 } 430 float threshold = sumKernel2 * poorFrac; // Threshold between poor and bad 431 432 // Get bounds of threshold region 433 // Start with the entire kernel, and keep reducing the size of the box until it drops below threshold 434 int box = kernels->size; // Size of box with bad pixels 435 for (double sumBox = sumKernel2; box > 0; box--) { 436 for (int x = -box; x <= box; x++) { 437 sumBox -= PS_SQR(kernel->kernel[-box][x]) + PS_SQR(kernel->kernel[box][x]); 438 } 439 for (int y = -box + 1; y <= box - 1; y++) { 440 // Note: not doing corners 441 sumBox -= PS_SQR(kernel->kernel[y][-box]) + PS_SQR(kernel->kernel[y][box]); 442 } 443 if (sumBox < threshold) { 444 break; 445 } 446 } 447 448 psFree(kernel); 449 450 return box; 451 } 452 453 psImage *p_pmSubtractionPolynomialFromCoords(psImage *output, const pmSubtractionKernels *kernels, 454 int numCols, int numRows, int x, int y) 455 { 456 assert(kernels); 457 assert(numCols > 0 && numRows > 0); 458 459 // Size to use when calculating normalised coordinates (different from actual size when convolving 460 // subimage) 461 int xNormSize = (kernels->numCols > 0 ? kernels->numCols : numCols); 462 int yNormSize = (kernels->numRows > 0 ? kernels->numRows : numRows); 463 464 // Normalised coordinates 465 float yNorm = 2.0 * (float)(y - yNormSize/2.0) / (float)yNormSize; 466 float xNorm = 2.0 * (float)(x - xNormSize/2.0) / (float)xNormSize; 467 468 return p_pmSubtractionPolynomial(output, kernels->spatialOrder, xNorm, yNorm); 432 469 } 433 470 … … 847 884 int xMin = region->x0, xMax = region->x1, yMin = region->y0, yMax = region->y1; // Bounds of patch 848 885 849 // Size to use when calculating normalised coordinates (different from actual size when convolving850 // subimage)851 int xNormSize = (kernels->numCols > 0 ? kernels->numCols : numCols);852 int yNormSize = (kernels->numRows > 0 ? kernels->numRows : numRows);853 854 // Normalised coordinates855 float yNorm = 2.0 * (float)(yMin + y0 + size + 1 - yNormSize/2.0) / (float)yNormSize; // Normalised coord856 float xNorm = 2.0 * (float)(xMin + x0 + size + 1 - xNormSize/2.0) / (float)xNormSize; // Normalised coord857 858 886 psKernel *kernelImage = NULL; // Kernel for the images 859 887 psKernel *kernelWeight = NULL; // Kernel for the weight maps … … 861 889 // Only generate polynomial values every kernel footprint, since we have already assumed 862 890 // (with the stamps) that it does not vary rapidly on this scale. 863 psImage *polyValues = p_pmSubtractionPolynomial(NULL, kernels->spatialOrder, 864 xNorm, yNorm); // Pre-calculated polynomial values 891 psImage *polyValues = p_pmSubtractionPolynomialFromCoords(NULL, kernels, numCols, numRows, 892 xMin + x0 + size + 1, 893 yMin + y0 + size + 1); 865 894 float background = doBG ? p_pmSubtractionSolutionBackground(kernels, polyValues) : 0.0; // Background term 866 895
Note:
See TracChangeset
for help on using the changeset viewer.
