IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 13, 2008, 2:13:09 PM (18 years ago)
Author:
Paul Price
Message:

Starting to attempt to support stacking of images that have been read in piecemeal (scan by scan). Added parameters to pmSubtractionKernels to specify size of the (original) image, so that normalisation can be done (during convolution) when the image size is not the original image size. Doing some algebraic gymnastics in the pixel rejection to account for the image being smaller than the original.

File:
1 edited

Legend:

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

    r16419 r16423  
    1111#define PIXEL_LIST_BUFFER 100           // Number of pixels to add to list at a time
    1212
    13 psPixels *pmStackReject(const psPixels *in, float threshold, const psArray *regions, const psArray *kernels)
     13psPixels *pmStackReject(const psPixels *in, const psRegion *valid, float threshold,
     14                        const psArray *subRegions, const psArray *kernels)
    1415{
    1516    PS_ASSERT_PIXELS_NON_NULL(in, NULL);
    1617    PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(threshold, 0.0, NULL);
    1718    PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(threshold, 1.0, NULL);
    18     PS_ASSERT_ARRAY_NON_NULL(regions, NULL);
     19    PS_ASSERT_ARRAY_NON_NULL(subRegions, NULL);
    1920    PS_ASSERT_ARRAY_NON_NULL(kernels, NULL);
    20     PS_ASSERT_ARRAYS_SIZE_EQUAL(regions, kernels, NULL);
     21    PS_ASSERT_ARRAYS_SIZE_EQUAL(subRegions, kernels, NULL);
    2122
    2223    // Get the original image size
    23     int numRegions = regions->n;        // Number of regions
     24    int numRegions = subRegions->n;        // Number of regions
    2425    int numCols = 0, numRows = 0;       // Size of original image
    2526    int minCols = INT_MAX, minRows = INT_MAX; // Minimum coordinate for image --- should be 0,0
    2627    int size = 0;                       // Size of kernel
    2728    for (int i = 0; i < numRegions; i++) {
    28         psRegion *region = regions->data[i]; // Region of interest
    29         if (region->x0 < minCols) {
    30             minCols = region->x0;
     29        psRegion *subRegion = subRegions->data[i]; // Region of interest
     30        if (subRegion->x0 < minCols) {
     31            minCols = subRegion->x0;
    3132        }
    32         if (region->y0 < minRows) {
    33             minRows = region->y0;
     33        if (subRegion->y0 < minRows) {
     34            minRows = subRegion->y0;
    3435        }
    35         if (region->x1 > numCols) {
    36             numCols = region->x1;
     36        if (subRegion->x1 > numCols) {
     37            numCols = subRegion->x1;
    3738        }
    38         if (region->y1 > numRows) {
    39             numRows = region->y1;
     39        if (subRegion->y1 > numRows) {
     40            numRows = subRegion->y1;
    4041        }
    4142
     
    4950        }
    5051    }
    51     if (minCols != 0 || minRows != 0) {
    52         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    53                 "Some error with image regions --- minimum coordinate is not 0,0");
    54         return NULL;
     52
     53    // Adjust the size for the size of the subimage
     54    if (valid) {
     55        minCols = PS_MAX(valid->x0, minCols);
     56        minRows = PS_MAX(valid->y0, minRows);
     57        numCols = PS_MIN(valid->x1, numCols);
     58        numRows = PS_MIN(valid->y1, numRows);
    5559    }
    5660
    57     psImage *mask = psPixelsToMask(NULL, in, psRegionSet(0, numCols, 0, numRows), 0x01); // Mask image
     61    psImage *mask = psPixelsToMask(NULL, in, psRegionSet(minCols, numCols, minRows, numRows), 0x01); // Mask
    5862    psImage *image = psImageCopy(NULL, mask, PS_TYPE_F32); // Floating-point version, so we can convolve
    5963    psFree(mask);
     
    6367    pmReadout *inRO = pmReadoutAlloc(NULL); // Readout with input image
    6468    inRO->image = image;
     69    inRO->col0 = minCols;
     70    inRO->row0 = minRows;
    6571    for (int i = 0; i < numRegions; i++) {
    66         psRegion *region = regions->data[i]; // Region of interest
     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)) {
     75            // Region is outside of our sub-image
     76            continue;
     77        }
    6778        pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest
    68         if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, region, kernel, true)) {
     79        if (!pmSubtractionConvolve(convRO, NULL, inRO, NULL, NULL, 0, subRegion, kernel, true)) {
    6980            psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i);
    7081            psFree(convRO);
     
    7788
    7889        // Image of the kernel at the centre of the region
    79         float xNorm = (region->x0 + 0.5 * (region->x1 - region->x0) - numCols/2.0) / (float)numCols;
    80         float yNorm = (region->y0 + 0.5 * (region->y1 - region->y0) - numRows/2.0) / (float)numRows;
     90        float xNorm = (subRegion->x0 + 0.5 * (subRegion->x1 - subRegion->x0) - kernel->numCols/2.0) /
     91            (float)kernel->numCols;
     92        float yNorm = (subRegion->y0 + 0.5 * (subRegion->y1 - subRegion->y0) - kernel->numRows/2.0) /
     93            (float)kernel->numRows;
    8194        psImage *image = pmSubtractionKernelImage(kernel, xNorm, yNorm, false);
    8295        if (!image) {
     
    94107        psFree(image);
    95108
    96         psImage *subConv = psImageSubset(convRO->image, *region); // Sub-image of convolved image
     109        psImage *subConv = psImageSubset(convRO->image, *subRegion); // Sub-image of convolved image
    97110        psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32));
    98111    }
     
    114127    // Now, grow the mask to include everything that touches a bad pixel in the convolution
    115128    mask = psPixelsToMask(NULL, bad, psRegionSet(0, numCols - 1, 0, numRows - 1), 0xff);
     129    assert(mask->numCols == numCols && mask->numRows == numRows);
    116130    for (int i = 0; i < bad->n; i++) {
    117131        int xPix = bad->data[i].x, yPix = bad->data[i].y; // Coordinates of interest
     
    123137        for (int y = yMin; y <= yMax; y++) {
    124138            for (int x = xMin; x <= xMax; x++) {
     139                assert(x < mask->numCols && y < mask->numRows);
    125140                mask->data.PS_TYPE_MASK_DATA[y][x] = 0xff;
    126141            }
Note: See TracChangeset for help on using the changeset viewer.