IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16423


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.

Location:
trunk/psModules/src/imcombine
Files:
5 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            }
  • trunk/psModules/src/imcombine/pmStackReject.h

    r16402 r16423  
    1010/// We apply a matched filter to the corresponding mask image, and threshold to find the original pixels
    1111psPixels *pmStackReject(const psPixels *in, ///< List of pixels in the convolved image
     12                        const psRegion *valid, ///< Valid region to consider
    1213                        float threshold, ///< Threshold on convolved image, 0..1
    1314                        const psArray *regions, ///< Array of image regions for image
  • trunk/psModules/src/imcombine/pmSubtraction.c

    r16352 r16423  
    44 *  @author GLG, MHPCC
    55 *
    6  *  @version $Revision: 1.77 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2008-02-07 04:03:23 $
     6 *  @version $Revision: 1.78 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2008-02-14 00:13:09 $
    88 *
    99 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
     
    715715
    716716    int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Image dimensions
     717    int x0 = ro1->col0, y0 = ro1->row0; // Image offset
    717718
    718719    psImage *convImage1 = out1->image;   // Convolved image
     
    771772        yMax = PS_MIN(region->y1, yMax);
    772773    }
     774
     775    // Size to use when calculating normalised coordinates (different from actual size when convolving
     776    // subimage)
     777    int xNormSize = (kernels->numCols > 0 ? kernels->numCols : numCols);
     778    int yNormSize = (kernels->numRows > 0 ? kernels->numRows : numRows);
    773779
    774780    psMaskType maskSource;              // Mask these pixels when convolving
     
    798804    for (int j = yMin; j < yMax; j += fullSize) {
    799805        int ySubMax = PS_MIN(j + fullSize, yMax); // Range for subregion of interest
    800         float yNorm = 2.0 * (float)(j + size + 1 - numRows/2.0) / (float)numRows; // Normalised coordinate
     806        float yNorm = 2.0 * (float)(j + y0 + size + 1 - yNormSize/2.0) /
     807            (float)yNormSize; // Normalised coordinate
    801808        for (int i = xMin; i < xMax; i += fullSize) {
    802809            int xSubMax = PS_MIN(i + fullSize, xMax); // Range for subregion of interest
    803             float xNorm = 2.0 * (float)(i + size + 1 - numCols/2.0) / (float)numCols; // Normalised coordinate
     810            float xNorm = 2.0 * (float)(i + x0 + size + 1 - xNormSize/2.0) /
     811                (float)xNormSize; // Normalised coordinate
    804812
    805813            // Only generate polynomial values every kernel footprint, since we have already assumed
  • trunk/psModules/src/imcombine/pmSubtractionKernels.c

    r15809 r16423  
    180180    kernels->bgOrder = 0;
    181181    kernels->mode = mode;
     182    kernels->numCols = 0;
     183    kernels->numRows = 0;
    182184    kernels->solution1 = NULL;
    183185    kernels->solution2 = NULL;
  • trunk/psModules/src/imcombine/pmSubtractionKernels.h

    r15756 r16423  
    3939    int bgOrder;                        ///< The order for the background fitting
    4040    pmSubtractionMode mode;             ///< Mode for subtraction
     41    int numCols, numRows;               ///< Size of image (for normalisation), or zero to use image provided
    4142    psVector *solution1, *solution2;    ///< Solution for the PSF matching
    4243} pmSubtractionKernels;
Note: See TracChangeset for help on using the changeset viewer.