IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15325


Ignore:
Timestamp:
Oct 16, 2007, 4:45:40 PM (19 years ago)
Author:
Paul Price
Message:

Allowing use of FFT convolution for masks. The program was spending a lot of time doing a direct convolution of the mask.

Location:
trunk/psModules/src/imcombine
Files:
3 edited

Legend:

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

    r15319 r15325  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-10-16 21:38:24 $
     6 *  @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-10-17 02:45:40 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    459459
    460460psImage *pmSubtractionMask(const psImage *refMask, const psImage *inMask, psMaskType maskVal,
    461                            int size, int footprint, float badFrac)
     461                           int size, int footprint, float badFrac, bool useFFT)
    462462{
    463463    PS_ASSERT_IMAGE_NON_NULL(refMask, NULL);
     
    540540    // skycell isn't overlapped by a large fraction by the observation), so that convolving around every bad
    541541    // pixel is wasting time.  As a first cut, I've put in a check on the fraction of bad pixels, but we could
    542     // imagine looking for the edge of big regions and convolving just at the edge.
    543 
    544     // Mask the bad pixels, and around them
     542    // imagine looking for the edge of big regions and convolving just at the edge.  As a second cut, allow
     543    // use of FFT convolution.
     544
    545545    for (int y = 0; y < numRows; y++) {
    546546        for (int x = 0; x < numCols; x++) {
    547547            if (inData && inData[y][x] & maskVal) {
    548548                maskData[y][x] |= PM_SUBTRACTION_MASK_INPUT;
    549                 // Block out the entire stamp footprint around this pixel
    550                 for (int v = PS_MAX(y - footprint, 0); v <= PS_MIN(y + footprint, numRows - 1); v++) {
    551                     for (int u = PS_MAX(x - footprint, 0); u <= PS_MIN(x + footprint, numCols - 1); u++) {
    552                         maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
    553                     }
    554                 }
    555549            }
    556550            if (refData[y][x] & maskVal) {
    557551                maskData[y][x] |= PM_SUBTRACTION_MASK_REF;
    558 
    559                 // We want to block out with the CONVOLVE mask anything that would be bad if we convolved with
    560                 // this bad pixel (within 'size').  Then we want to block out with the FOOTPRINT mask
    561                 // everything within a footprint's distance of those (within 'footprint').
    562 
    563                 // Bottom stripe
    564                 for (int v = PS_MAX(y - footprint - size, 0); v < y - size; v++) {
    565                     for (int u = PS_MAX(x - footprint - size, 0);
    566                          u <= PS_MIN(x + footprint + size, numCols - 1); u++) {
    567                         maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
    568                     }
    569                 }
    570                 // Middle
    571                 for (int v = PS_MAX(y - size, 0); v <= PS_MIN(y + size, numRows - 1); v++) {
    572                     // Left side
    573                     for (int u = PS_MAX(x - footprint - size, 0); u < x - size; u++) {
    574                         maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
    575                     }
    576                     // Centre
    577                     for (int u = PS_MAX(x - size, 0); u <= PS_MIN(x + size, numCols - 1); u++) {
    578                         maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT | PM_SUBTRACTION_MASK_CONVOLVE;
    579                     }
    580                     // Right side
    581                     for (int u = x + size + 1; u <= PS_MIN(x + footprint + size, numCols - 1); u++) {
    582                         maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
    583                     }
    584                 }
    585                 // Top stripe
    586                 for (int v = y + size + 1; v <= PS_MIN(y + footprint + size, numRows - 1); v++) {
    587                     for (int u = PS_MAX(x - footprint - size, 0);
    588                          u <= PS_MIN(x + footprint + size, numCols - 1); u++) {
    589                         maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
    590                     }
    591                 }
    592             }
     552            }
     553        }
     554    }
     555
     556    // Block out the entire stamp footprint around bad input pixels.
     557
     558    // We want to block out with the CONVOLVE mask anything that would be bad if we convolved with a bad
     559    // reference pixel (within 'size').  Then we want to block out with the FOOTPRINT mask everything within a
     560    // footprint's distance of those (within 'footprint').
     561
     562    if (useFFT) {
     563        if (!psImageConvolveMaskFFT(mask, mask, PM_SUBTRACTION_MASK_INPUT, PM_SUBTRACTION_MASK_FOOTPRINT,
     564                                    -footprint, footprint, -footprint, footprint, 0.5)) {
     565            psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad input pixels.");
     566            psFree(mask);
     567            return NULL;
     568        }
     569        if (!psImageConvolveMaskFFT(mask, mask, PM_SUBTRACTION_MASK_REF, PM_SUBTRACTION_MASK_CONVOLVE,
     570                                    -size, size, -size, size, 0.5)) {
     571            psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad reference pixels.");
     572            psFree(mask);
     573            return NULL;
     574        }
     575        if (!psImageConvolveMaskFFT(mask, mask, PM_SUBTRACTION_MASK_CONVOLVE, PM_SUBTRACTION_MASK_FOOTPRINT,
     576                                    -footprint, footprint, -footprint, footprint, 0.5)) {
     577            psError(PS_ERR_UNKNOWN, false, "Unable to reconvolve bad reference pixels.");
     578            psFree(mask);
     579            return NULL;
     580        }
     581    } else {
     582        if (!psImageConvolveMaskDirect(mask, mask, PM_SUBTRACTION_MASK_INPUT, PM_SUBTRACTION_MASK_FOOTPRINT,
     583                                       -footprint, footprint, -footprint, footprint)) {
     584            psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad input pixels.");
     585            psFree(mask);
     586            return NULL;
     587        }
     588        if (!psImageConvolveMaskDirect(mask, mask, PM_SUBTRACTION_MASK_REF, PM_SUBTRACTION_MASK_CONVOLVE,
     589                                   -size, size, -size, size)) {
     590            psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad reference pixels.");
     591            psFree(mask);
     592            return NULL;
     593        }
     594        if (!psImageConvolveMaskDirect(mask, mask, PM_SUBTRACTION_MASK_CONVOLVE,
     595                                       PM_SUBTRACTION_MASK_FOOTPRINT,
     596                                       -footprint, footprint, -footprint, footprint)) {
     597            psError(PS_ERR_UNKNOWN, false, "Unable to reconvolve bad reference pixels.");
     598            psFree(mask);
     599            return NULL;
    593600        }
    594601    }
  • trunk/psModules/src/imcombine/pmSubtraction.h

    r15305 r15325  
    66 * @author GLG, MHPCC
    77 *
    8  * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    9  * @date $Date: 2007-10-12 23:00:37 $
     8 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     9 * @date $Date: 2007-10-17 02:45:40 $
    1010 *
    1111 * Copyright 2004-207 Institute for Astronomy, University of Hawaii
     
    3838                           int size, ///< Half-size of the kernel (pmSubtractionKernels.size)
    3939                           int footprint, ///< Half-size of the kernel footprint
    40                            float badFrac ///< Maximum fraction of bad input pixels to accept
     40                           float badFrac, ///< Maximum fraction of bad input pixels to accept
     41                           bool useFFT  ///< Use FFT to do convolution?
    4142    );
    4243
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r15305 r15325  
    1515#include "pmSubtraction.h"
    1616#include "pmSubtractionMatch.h"
     17
     18
     19static bool useFFT = true;              // Do convolutions using FFT
    1720
    1821
     
    223226    memCheck("start");
    224227
    225     subMask = pmSubtractionMask(reference->mask, inMask, maskBad, size, footprint, badFrac);
    226     if (subMask) {
     228    subMask = pmSubtractionMask(reference->mask, inMask, maskBad, size, footprint, badFrac, useFFT);
     229    if (!subMask) {
    227230        psError(PS_ERR_UNKNOWN, false, "Unable to generate subtraction mask.");
    228231        return false;
     
    417420            if (!pmSubtractionConvolve(&convolved->image, &convolved->weight, &convolved->mask,
    418421                                       reference->image, reference->weight, subMask, maskBlank, region,
    419                                        solution, kernels, true)) {
     422                                       solution, kernels, useFFT)) {
    420423                psError(PS_ERR_UNKNOWN, false, "Unable to convolve reference image.");
    421424                goto ERROR;
Note: See TracChangeset for help on using the changeset viewer.