IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 22, 2007, 3:59:31 PM (19 years ago)
Author:
Paul Price
Message:

Adding check on return of pmSubtractionKernelImage.
Fixing coordinates (supposed to be -1..1).
Moving thresholding out of loop (if we need to keep the
entire convolved image, we may as well threshold once).

File:
1 edited

Legend:

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

    r14602 r14623  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-08-22 02:56:53 $
     6 *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-08-23 01:59:31 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    10641064
    10651065    // Convolve the image with the kernel --- we're basically applying a matched filter and then thresholding
    1066     psImage *convolved = NULL;          // Convolved mask image
    10671066    psPixels *out = NULL;               // List of pixels that should be masked
    10681067    for (int i = 0; i < numRegions; i++) {
     
    10791078        // the kernel may scale the unit level that we've inserted.
    10801079
    1081         // Image of the kernel at the centre
    1082         psImage *kernel = pmSubtractionKernelImage(solution, kernels,
    1083                                                    region->x0 + 0.5 * (region->x1 - region->x0),
    1084                                                    region->y0 + 0.5 * (region->y1 - region->y0));
     1080        // Image of the kernel at the centre of the region
     1081        float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - numCols/2.0) / (float)numCols;
     1082        float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - numRows/2.0) / (float)numRows;
     1083        psImage *kernel = pmSubtractionKernelImage(solution, kernels, xNorm, yNorm);
     1084        if (!kernel) {
     1085            psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image.");
     1086            psFree(convolved);
     1087            psFree(image);
     1088            return NULL;
     1089        }
    10851090        float sum = 0.0;
    10861091        for (int y = 0; y < kernel->numRows; y++) {
     
    10911096        psFree(kernel);
    10921097
    1093         // Threshold the convolved image
    1094         float adjustedThreshold = sum * threshold; // Threshold adjusted for the kernel normalisation
    1095         for (int y = region->y0; y < region->y1; y++) {
    1096             for (int x = region->x0; x < region->x1; x++) {
    1097                 if (image->data.F32[y][x] > adjustedThreshold) {
    1098                     out = psPixelsAdd(out, PIXEL_LIST_BUFFER, x, y);
    1099                 }
    1100             }
    1101         }
     1098        psImage *subConv = psImageSubset(convolved, *region); // Sub-image of convolved image
     1099        psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32));
    11021100    }
    11031101    psFree(image);
    11041102
     1103    // Threshold the convolved image
     1104    for (int y = 0; y < numRows; y++) {
     1105        for (int x = 0; x < numCols; x++) {
     1106            if (convolved->data.F32[y][x] > threshold) {
     1107                out = psPixelsAdd(out, PIXEL_LIST_BUFFER, x, y);
     1108            }
     1109        }
     1110    }
     1111    psFree(convolved);
     1112
    11051113    return out;
    11061114}
Note: See TracChangeset for help on using the changeset viewer.