IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2008, 1:18:34 PM (18 years ago)
Author:
Paul Price
Message:

Fixing regions to allow convolution of sub-images (for ppStack)

File:
1 edited

Legend:

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

    r16423 r16476  
    5959    }
    6060
    61     psImage *mask = psPixelsToMask(NULL, in, psRegionSet(minCols, numCols, minRows, numRows), 0x01); // Mask
     61    psImage *mask = psPixelsToMask(NULL, in, psRegionSet(minCols, numCols - 1, minRows, numRows - 1),
     62                                   0x01); // Mask
    6263    psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve
    6364    psFree(mask);
     
    7071    inRO->row0 = minRows;
    7172    for (int i = 0; i < numRegions; i++) {
    72         psRegion *subRegion = subRegions->data[i]; // Region of interest
    73         if (valid && (subRegion->x0 > valid->x1 || subRegion->x1 < valid->x0 ||
    74                       subRegion->y0 > valid->y1 || subRegion->y1 < valid->y0)) {
     73        psRegion *region = subRegions->data[i]; // Region of interest
     74        if (valid && (region->x0 > valid->x1 || region->x1 < valid->x0 ||
     75                      region->y0 > valid->y1 || region->y1 < valid->y0)) {
    7576            // Region is outside of our sub-image
    7677            continue;
    7778        }
    7879        pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest
    79         if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, subRegion, kernel, true)) {
     80        if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernel, true)) {
    8081            psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i);
    8182            psFree(convRO);
     
    8889
    8990        // Image of the kernel at the centre of the region
    90         float xNorm = (subRegion->x0 + 0.5 * (subRegion->x1 - subRegion->x0) - kernel->numCols/2.0) /
     91        float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - kernel->numCols/2.0) /
    9192            (float)kernel->numCols;
    92         float yNorm = (subRegion->y0 + 0.5 * (subRegion->y1 - subRegion->y0) - kernel->numRows/2.0) /
     93        float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - kernel->numRows/2.0) /
    9394            (float)kernel->numRows;
    9495        psImage *image = pmSubtractionKernelImage(kernel, xNorm, yNorm, false);
     
    107108        psFree(image);
    108109
    109         psImage *subConv = psImageSubset(convRO->image, *subRegion); // Sub-image of convolved image
    110         psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32));
     110        // Range for normalisation
     111        int yMin = PS_MAX(minRows, region->y0) - inRO->row0;
     112        int yMax = PS_MIN(numRows - 1, region->y1) - inRO->row0;
     113        int xMin = PS_MAX(minCols, region->x0) - inRO->col0;
     114        int xMax = PS_MIN(numCols - 1, region->x1) - inRO->col0;
     115        psTrace("psModules.imcombine", 2, "Normalising convolved mask image by %f over %d:%d,%d:%d\n",
     116                sum, xMin, xMax, yMin, yMax);
     117        for (int y = yMin; y <= yMax; y++) {
     118            for (int x = xMin; x <= xMax; x++) {
     119                convRO->image->data.F32[y][x] /= sum;
     120            }
     121        }
    111122    }
    112123    psFree(inRO);
     
    116127    // Threshold the convolved image
    117128    psPixels *bad = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); // List of pixels that should be masked
    118     for (int y = 0; y < numRows; y++) {
    119         for (int x = 0; x < numCols; x++) {
     129    for (int y = 0; y < convolved->numRows; y++) {
     130        for (int x = 0; x < convolved->numCols; x++) {
    120131            if (convolved->data.F32[y][x] > threshold) {
    121132                bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x, y);
Note: See TracChangeset for help on using the changeset viewer.