IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 13, 2007, 10:28:28 AM (19 years ago)
Author:
Paul Price
Message:

Restoring changes that were wiped when uploading the code to provide additional kernels.

File:
1 edited

Legend:

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

    r14125 r14195  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-07-11 01:28:39 $
     6 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-07-13 20:28:28 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    410410//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    411411
     412psImage *pmSubtractionMask(const psImage *inMask, const psImage *refMask, psMaskType maskVal,
     413                           int size, int footprint)
     414{
     415    PS_ASSERT_IMAGE_NON_NULL(inMask, NULL);
     416    PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_MASK, NULL);
     417    PS_ASSERT_IMAGE_NON_NULL(refMask, NULL);
     418    PS_ASSERT_IMAGE_TYPE(refMask, PS_TYPE_MASK, NULL);
     419    PS_ASSERT_IMAGES_SIZE_EQUAL(inMask, refMask, NULL);
     420    PS_ASSERT_INT_NONNEGATIVE(size, NULL);
     421    PS_ASSERT_INT_NONNEGATIVE(footprint, NULL);
     422
     423    // Size of the images
     424    int numCols = inMask->numCols;
     425    int numRows = inMask->numRows;
     426
     427    // Worried about the masks for bad pixels and bad stamps colliding, so make our own mask
     428    psImage *mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // The global mask
     429    psImageInit(mask, 0);
     430
     431    // Dereference for convenience
     432    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA;
     433    psMaskType **inData = inMask->data.PS_TYPE_MASK_DATA;
     434    psMaskType **refData = refMask->data.PS_TYPE_MASK_DATA;
     435
     436    // Block out a border around the edge of the image
     437
     438    // Bottom stripe
     439    for (int y = 0; y < PS_MIN(size + footprint, numRows); y++) {
     440        for (int x = 0; x < numCols; x++) {
     441            maskData[y][x] |= PM_SUBTRACTION_MASK_BORDER;
     442        }
     443    }
     444    // Either side
     445    for (int y = PS_MIN(size + footprint, numRows); y < numRows - size - footprint; y++) {
     446        for (int x = 0; x < PS_MIN(size + footprint, numCols); x++) {
     447            maskData[y][x] |= PM_SUBTRACTION_MASK_BORDER;
     448        }
     449        for (int x = PS_MAX(numCols - size - footprint, 0); x < numCols; x++) {
     450            maskData[y][x] |= PM_SUBTRACTION_MASK_BORDER;
     451        }
     452    }
     453    // Top stripe
     454    for (int y = PS_MAX(numRows - size - footprint, 0); y < numRows; y++) {
     455        for (int x = 0; x < numCols; x++) {
     456            maskData[y][x] |= PM_SUBTRACTION_MASK_BORDER;
     457        }
     458    }
     459
     460    // Mask the bad pixels, and around them
     461    for (int y = footprint + size; y < numRows - footprint - size; y++) {
     462        for (int x = 0; x < numCols; x++) {
     463            if (inData[y][x] & maskVal) {
     464                maskData[y][x] |= PM_SUBTRACTION_MASK_INPUT;
     465                // Block out the entire stamp footprint around this pixel
     466                for (int v = y - footprint; v <= y + footprint; v++) {
     467                    for (int u = x - footprint; u <= x + footprint; u++) {
     468                        maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
     469                    }
     470                }
     471            }
     472            if (refData[y][x] & maskVal) {
     473                maskData[y][x] |= PM_SUBTRACTION_MASK_REF;
     474
     475                // We want to block out with the CONVOLVE mask anything that would be bad if we convolved with
     476                // this bad pixel (within 'size').  Then we want to block out with the FOOTPRINT mask
     477                // everything within a footprint's distance of those (within 'footprint').
     478
     479                // Bottom stripe
     480                for (int v = PS_MAX(y - footprint - size, 0); v < y - size; v++) {
     481                    for (int u = PS_MAX(x - footprint - size, 0);
     482                         u <= PS_MIN(x + footprint + size, numCols - 1); u++) {
     483                        maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
     484                    }
     485                }
     486                // Middle
     487                for (int v = PS_MAX(y - size, 0); v <= PS_MIN(y + size, numRows - 1); v++) {
     488                    // Left side
     489                    for (int u = PS_MAX(x - footprint - size, 0); u < x - size; u++) {
     490                        maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
     491                    }
     492                    // Centre
     493                    for (int u = PS_MAX(x - size, 0); u <= PS_MIN(x + size, numCols - 1); u++) {
     494                        maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT | PM_SUBTRACTION_MASK_CONVOLVE;
     495                    }
     496                    // Right side
     497                    for (int u = x + size + 1; u <= PS_MIN(x + footprint + size, numCols - 1); u++) {
     498                        maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
     499                    }
     500                }
     501                // Top stripe
     502                for (int v = y + size + 1; v <= PS_MIN(y + footprint + size, numRows - 1); v++) {
     503                    for (int u = PS_MAX(x - footprint - size, 0);
     504                         u <= PS_MIN(x + footprint + size, numCols - 1); u++) {
     505                        maskData[v][u] |= PM_SUBTRACTION_MASK_FOOTPRINT;
     506                    }
     507                }
     508            }
     509        }
     510    }
     511
     512    return mask;
     513}
     514
     515
    412516bool pmSubtractionCalculateEquation(psArray *stamps, const psImage *reference, const psImage *input,
    413517                                    const psImage *weight, const pmSubtractionKernels *kernels, int footprint)
     
    507611            psFree(polyValues);
    508612
    509             // Fill in lower diagonal of symmetric matrix
     613            // Fill in lower diagonal of symmetric matrix, while checking for bad values
     614            bool bad = false;           // Are there bad values?
    510615            for (int i = 0; i < numKernels; i++) {
    511616                for (int j = 0; j < i; j++) {
    512617                    stampMatrix->data.F64[i][j] = stampMatrix->data.F64[j][i];
     618                    if (!isfinite(stampMatrix->data.F64[j][i])) {
     619                        bad = true;
     620                    }
    513621                }
    514622                stampMatrix->data.F64[bgIndex][i] = stampMatrix->data.F64[i][bgIndex];
    515             }
    516 
    517             stamp->status = PM_SUBTRACTION_STAMP_USED;
     623                if (!isfinite(stampMatrix->data.F64[i][bgIndex]) ||
     624                    !isfinite(stampMatrix->data.F64[i][i]) ||
     625                    !isfinite(stampVector->data.F64[i])) {
     626                    bad = true;
     627                }
     628            }
     629            if (!isfinite(stampVector->data.F64[bgIndex])) {
     630                bad = true;
     631            }
     632
     633            if (bad) {
     634                stamp->status = PM_SUBTRACTION_STAMP_REJECTED;
     635                psTrace("psModules.imcombine", 3, "Rejecting stamp %d because of bad equation\n", i);
     636            } else {
     637                stamp->status = PM_SUBTRACTION_STAMP_USED;
     638            }
    518639
    519640            if (psTraceGetLevel("psModules.imcombine.equation") >= 10) {
     
    610731
    611732int pmSubtractionRejectStamps(psArray *stamps, const psImage *refImage, psImage *inImage,
    612                               psImage *mask, psMaskType badStampMaskVal, const psVector *solution,
    613                               int footprint, float sigmaRej, const pmSubtractionKernels *kernels)
     733                              psImage *subMask, const psVector *solution, int footprint, float sigmaRej,
     734                              const pmSubtractionKernels *kernels)
    614735{
    615736    PS_ASSERT_ARRAY_NON_NULL(stamps, -1);
     
    619740    PS_ASSERT_IMAGE_TYPE(inImage, PS_TYPE_F32, -1);
    620741    PS_ASSERT_IMAGES_SIZE_EQUAL(refImage, inImage, -1);
    621     PS_ASSERT_IMAGE_NON_EMPTY(mask, -1);
    622     PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, -1);
    623     PS_ASSERT_IMAGES_SIZE_EQUAL(refImage, mask, -1);
     742    PS_ASSERT_IMAGE_NON_EMPTY(subMask, -1);
     743    PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, -1);
     744    PS_ASSERT_IMAGES_SIZE_EQUAL(refImage, subMask, -1);
    624745    PS_ASSERT_VECTOR_NON_NULL(solution, -1);
    625746    PS_ASSERT_VECTOR_TYPE(solution, PS_TYPE_F64, -1);
     
    714835            for (int y = stamp->y - footprint; y <= stamp->y + footprint; y++) {
    715836                for (int x = stamp->x - footprint; x <= stamp->x + footprint; x++) {
    716                     mask->data.PS_TYPE_MASK_DATA[y][x] |= badStampMaskVal;
     837                    subMask->data.PS_TYPE_MASK_DATA[y][x] |= PM_SUBTRACTION_MASK_REJ;
    717838                }
    718839            }
     
    767888
    768889bool pmSubtractionConvolve(psImage **outImage, psImage **outWeight, psImage **outMask,
    769                            const psImage *inImage, const psImage *inWeight, const psImage *inMask,
    770                            psMaskType maskVal, psMaskType blank,
    771                            const psVector *solution, const pmSubtractionKernels *kernels)
     890                           const psImage *inImage, const psImage *inWeight, const psImage *subMask,
     891                           psMaskType blank, const psVector *solution, const pmSubtractionKernels *kernels)
    772892{
    773893    PS_ASSERT_IMAGE_NON_NULL(inImage, false);
    774894    PS_ASSERT_IMAGE_TYPE(inImage, PS_TYPE_F32, false);
    775     if (inMask) {
    776         PS_ASSERT_IMAGE_NON_NULL(inMask, false);
    777         PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_MASK, false);
    778         PS_ASSERT_IMAGES_SIZE_EQUAL(inMask, inImage, false);
     895    if (subMask) {
     896        PS_ASSERT_IMAGE_NON_NULL(subMask, false);
     897        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, false);
     898        PS_ASSERT_IMAGES_SIZE_EQUAL(subMask, inImage, false);
    779899    }
    780900    if (inWeight) {
     
    793913        PS_ASSERT_IMAGES_SIZE_EQUAL(*outMask, inImage, false);
    794914        PS_ASSERT_IMAGE_TYPE(*outMask, PS_TYPE_MASK, false);
    795         PS_ASSERT_IMAGE_NON_NULL(inMask, false);
     915        PS_ASSERT_IMAGE_NON_NULL(subMask, false);
    796916    }
    797917    if (outWeight && *outWeight) {
     
    823943    }
    824944    psImage *convMask = NULL;           // Convolved mask image
    825     if (outMask && inMask) {
     945    if (outMask && subMask) {
    826946        if (!*outMask) {
    827947            *outMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     
    872992
    873993                    // Check and propagate the kernel footprint, if required
    874                     if (inMask) {
    875                         for (int v = -size; v <= size; v++) {
    876                             for (int u = -size; u <= size; u++) {
    877                                 convMask->data.PS_TYPE_MASK_DATA[y][x] |=
    878                                     inMask->data.PS_TYPE_MASK_DATA[y + v][x + u];
    879                             }
    880                         }
    881                         if (convMask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
    882                             convImage->data.F32[y][x] = NAN;
    883                             if (inWeight) {
    884                                 convWeight->data.F32[y][x] = NAN;
    885                             }
    886                             continue;
     994                    if (subMask && (subMask->data.PS_TYPE_MASK_DATA[y][x] &
     995                                    (PM_SUBTRACTION_MASK_INPUT | PM_SUBTRACTION_MASK_CONVOLVE))) {
     996                        convMask->data.PS_TYPE_MASK_DATA[y][x] |= blank;
     997                        convImage->data.F32[y][x] = NAN;
     998                        if (inWeight) {
     999                            convWeight->data.F32[y][x] = NAN;
    8871000                        }
    8881001                    }
Note: See TracChangeset for help on using the changeset viewer.