IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 22, 2008, 9:24:42 AM (18 years ago)
Author:
Paul Price
Message:

Merging in ppStack development branch --- ppStack now works with incremental reads. Small conflicts (due to stupid patch application by CVS) resolved.

File:
1 edited

Legend:

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

    r16479 r16604  
    2525    int numRegions = regions->n;        // Number of regions
    2626    int numCols = 0, numRows = 0;       // Size of original image
    27     int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0
     27    int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image
     28    int size = 0;                       // Size of kernel
    2829    for (int i = 0; i < numRegions; i++) {
    2930        psRegion *region = regions->data[i]; // Region of interest
     
    4647        return NULL;
    4748    }
     49    psTrace("psModules.imcombine", 1, "Rejecting [%d:%d,%d:%d]\n", minCols, numCols, minRows, numRows);
    4850
    4951    psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image
     
    5658    inRO->image = image;
    5759    for (int i = 0; i < numRegions; i++) {
    58         psRegion *region = regions->data[i]; // Region of interest
    59         if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernels, true)) {
     60        psRegion *region = subRegions->data[i]; // Region of interest
     61        if (valid && (region->x0 > valid->x1 || region->x1 < valid->x0 ||
     62                      region->y0 > valid->y1 || region->y1 < valid->y0)) {
     63            // Region is outside of our sub-image
     64            continue;
     65        }
     66        pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest
     67        if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernel, false, true)) {
    6068            psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i);
    6169            psFree(convRO);
     
    94102    // Threshold the convolved image
    95103    psPixels *bad = psPixelsAllocEmpty(PIXEL_LIST_BUFFER); // List of pixels that should be masked
    96     for (int y = 0; y < numRows; y++) {
    97         for (int x = 0; x < numCols; x++) {
     104    for (int y = size; y < convolved->numRows - size; y++) {
     105        for (int x = size; x < convolved->numCols - size; x++) {
    98106            if (convolved->data.F32[y][x] > threshold) {
    99                 bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x, y);
     107                // Pixel coordinates in "bad" correspond to the full image
     108                bad = psPixelsAdd(bad, PIXEL_LIST_BUFFER, x + minCols, y + minRows);
    100109            }
    101110        }
     
    103112    psFree(convolved);
    104113
    105     // Now, we want to convolve the original pixels properly
    106     mask = psPixelsToMask(NULL, bad, psRegionSet(0, numCols, 0, numRows), 0xff);
    107     int size = kernels->size;           // Size of kernels
     114    // Now, grow the mask to include everything that touches a bad pixel in the convolution
     115    int x0 = minCols, y0 = minRows;     // Offset for mask image
     116    mask = psPixelsToMask(NULL, bad, psRegionSet(x0, numCols - 1, y0, numRows - 1), 0xff);
    108117    for (int i = 0; i < bad->n; i++) {
    109         int xPix = bad->data[i].x, yPix = bad->data[i].y; // Coordinates of interest
     118        int xPix = bad->data[i].x - x0, yPix = bad->data[i].y - y0; // Coordinates in frame of mask image
    110119        // Convolution limits
    111120        int xMin = PS_MAX(xPix - size, 0);
    112         int xMax = PS_MIN(xPix + size, numCols - 1);
     121        int xMax = PS_MIN(xPix + size, mask->numCols - 1);
    113122        int yMin = PS_MAX(yPix - size, 0);
    114         int yMax = PS_MIN(yPix + size, numRows - 1);
     123        int yMax = PS_MIN(yPix + size, mask->numRows - 1);
    115124        for (int y = yMin; y <= yMax; y++) {
    116125            for (int x = xMin; x <= xMax; x++) {
     
    119128        }
    120129    }
    121 
    122130    bad = psPixelsFromMask(bad, mask, 0xff);
    123131    psFree(mask);
    124132
     133    // Convert coordinates to frame of original image
     134    for (int i = 0; i < bad->n; i++) {
     135        int x = bad->data[i].x + x0;
     136        int y = bad->data[i].y + y0;
     137        if (x < 0 || x >= numCols || y < 0 || y >= numRows) {
     138            psWarning("Bad pixel coordinate %d: %d,%d --- ignored.",
     139                      i, x, y);
     140            continue;
     141        }
     142        bad->data[i].x = x;
     143        bad->data[i].y = y;
     144    }
     145
    125146    return bad;
    126147}
Note: See TracChangeset for help on using the changeset viewer.