IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 28, 2008, 6:04:19 PM (18 years ago)
Author:
Paul Price
Message:

We want a bad/poor mask distinction in the mask convolution for stacking. Again, otherwise the number of bad pixels just explodes. Since convolving a mask with the PSF-matching kernel is something we want to do in both stack rejection and normal convolution, pulled the code that determines the size of the 'bad' region into a separate function in pmSubtraction.c. Then pmStackReject basically does the same thing that's happening in pmSubtractionConvolve/convolveRegion: go through the image by footprints, convolve the footprint and plug the result back in to the original image. Small API change for pmStackReject. This is very effective in reducing the amount of bad pixels in the stacked image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r19271 r19282  
    300300                                  psImage *subMask, // Subtraction mask
    301301                                  const pmSubtractionKernels *kernels, // Kernels
    302                                   psImage *polyValues, // Polynomial values
     302                                  const psImage *polyValues, // Polynomial values
    303303                                  float background, // Background value to apply
    304304                                  psRegion region, // Region to convolve
     
    340340    // Convolve the mask for bad pixels
    341341    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
    370344        if (box > 0) {
    371345            int colMin = region.x0, colMax = region.x1, rowMin = region.y0, rowMax = region.y1; // Bounds
     
    415389    return;
    416390}
     391
     392
    417393
    418394//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    430406    psFree(conv);
    431407    return convolved;
     408}
     409
     410int 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
     453psImage *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);
    432469}
    433470
     
    847884    int xMin = region->x0, xMax = region->x1, yMin = region->y0, yMax = region->y1; // Bounds of patch
    848885
    849     // Size to use when calculating normalised coordinates (different from actual size when convolving
    850     // subimage)
    851     int xNormSize = (kernels->numCols > 0 ? kernels->numCols : numCols);
    852     int yNormSize = (kernels->numRows > 0 ? kernels->numRows : numRows);
    853 
    854     // Normalised coordinates
    855     float yNorm = 2.0 * (float)(yMin + y0 + size + 1 - yNormSize/2.0) / (float)yNormSize; // Normalised coord
    856     float xNorm = 2.0 * (float)(xMin + x0 + size + 1 - xNormSize/2.0) / (float)xNormSize; // Normalised coord
    857 
    858886    psKernel *kernelImage = NULL;       // Kernel for the images
    859887    psKernel *kernelWeight = NULL;      // Kernel for the weight maps
     
    861889    // Only generate polynomial values every kernel footprint, since we have already assumed
    862890    // (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);
    865894    float background = doBG ? p_pmSubtractionSolutionBackground(kernels, polyValues) : 0.0; // Background term
    866895
Note: See TracChangeset for help on using the changeset viewer.