IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 5, 2008, 12:37:59 PM (18 years ago)
Author:
Paul Price
Message:

Fixed a bug in the tile transformation that was resulting in transformed data being overwritten with untransformed data (a single character bug --- 'y' instead of 'x'!). Attempted to make transformations a bit more efficient by only transforming the tiles that overlap the image; doesn't seem to make much difference.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpTransformTile.c

    r19149 r19395  
    1 # include "pswarp.h"
     1#include "pswarp.h"
    22
    3 void pswarpTransformTileArgsFree (pswarpTransformTileArgs *args) {
    4     if (!args) return;
     3static void transformTileArgsFree(pswarpTransformTileArgs *args)
     4{
     5    psFree(args->input);
     6    psFree(args->output);
     7    psFree(args->grid);
     8    psFree(args->interp);
     9    psFree(args->region);
    510    return;
    611}
    712
    8 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc() {
    9 
    10     pswarpTransformTileArgs *args = (pswarpTransformTileArgs *)psAlloc(sizeof(pswarpTransformTileArgs));
    11     psMemSetDeallocator(args, (psFreeFunc)pswarpTransformTileArgsFree);
     13pswarpTransformTileArgs *pswarpTransformTileArgsAlloc()
     14{
     15    pswarpTransformTileArgs *args = psAlloc(sizeof(pswarpTransformTileArgs));
     16    psMemSetDeallocator(args, (psFreeFunc)transformTileArgsFree);
    1217
    1318    args->input = NULL;
     
    2126
    2227    args->goodPixels = 0;
     28    args->xMin = PS_MAX_S32;
     29    args->xMax = PS_MIN_S32;
     30    args->yMin = PS_MAX_S32;
     31    args->yMax = PS_MIN_S32;
    2332
    2433    return args;
    2534}
    2635
    27 bool pswarpTransformTile (pswarpTransformTileArgs *args) {
     36bool pswarpTransformTile(pswarpTransformTileArgs *args)
     37{
     38    psImage *inImage = args->input->image; // Input image
     39    psImage *outImage = args->output->image; // Output image
    2840
    29     // int inCol0 = args->input->image->col0;
    30     // int inRow0 = args->input->image->row0;
    31     int inNcol = args->input->image->numCols;
    32     int inNrow = args->input->image->numRows;
     41    int inNumCols = inImage->numCols, inNumRows = inImage->numRows; // Size of input image
     42    int outNumCols = outImage->numCols, outNumRows = outImage->numRows; // Size of output image
     43    int outCol0 = outImage->col0, outRow0 = outImage->row0; // Offset of output image
    3344
    34     int outCol0 = args->output->image->col0;
    35     int outRow0 = args->output->image->row0;
    36     int outNcol = args->output->image->numCols;
    37     int outNrow = args->output->image->numRows;
     45    psPlane minPt, maxPt;               // Minimum and maximum points for this tile
     46    pswarpMapGridCoordRange(args->grid, args->gridX, args->gridY, &minPt, &maxPt);
    3847
    39     // get the coordinate range for this grid tile
    40     psPlane minPt, maxPt;
    41     pswarpMapGridCoordRange (args->grid, args->gridX, args->gridY, &minPt, &maxPt);
    42 
    43     psF32 **outImageData     = (args->output->image)  ? args->output->image->data.F32 : NULL;
     48    // Dereference images for convenience
     49    psF32 **outImageData     = args->output->image->data.F32;
    4450    psF32 **outVarData       = (args->output->weight) ? args->output->weight->data.F32 : NULL;
    4551    psMaskType **outMaskData = (args->output->mask)   ? args->output->mask->data.PS_TYPE_MASK_DATA : NULL;
    4652    psMaskType **inMaskData  = (args->input->mask)    ? args->input->mask->data.PS_TYPE_MASK_DATA : NULL;
    4753
    48     pswarpMap *map = args->grid->maps[args->gridX][args->gridY];
    49 
    50     psImage *region = args->region;
    51 
    52     double xInRaw, yInRaw;
    53 
    54     // output values for this pixel
    55     double imageValue;
    56     double varValue;
    57     psMaskType maskValue;
     54    pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; // Map for this tile
     55    psImage *region = args->region;     // Region to transform
    5856
    5957    // Bounds for iteration
    6058    int xMin = PS_MAX(minPt.x, 0);
    61     int xMax = PS_MIN(maxPt.x, outNcol);
     59    int xMax = PS_MIN(maxPt.x, outNumCols);
    6260    int yMin = PS_MAX(minPt.y, 0);
    63     int yMax = PS_MIN(maxPt.y, outNrow);
    64 
     61    int yMax = PS_MIN(maxPt.y, outNumRows);
    6562
    6663    // Iterate over the output image pixels (parent frame)
     
    7067
    7168            // Only transform those pixels requested
    72             if (region && region->data.U8[y][x]) continue;
     69            if (region && region->data.U8[y][x]) {
     70                continue;
     71            }
    7372
    7473            // pswarpMapApply converts the output coordinate (x,y) to the input coordinate.
    7574            // both are in the parent frames of the input and output images.
    76             pswarpMapApply (&xInRaw, &yInRaw, map, x + 0.5, y + 0.5);
    77 
    78             double xIn = xInRaw - outCol0;      // Position on input image
    79             double yIn = yInRaw - outRow0;      // Position on input image
    80 
    81             if (xIn < 0) continue;
    82             if (yIn >= inNcol) continue;
    83             if (yIn < 0) continue;
    84             if (yIn >= inNrow) continue;
    85 
    86             goodPixels++;
     75            double xInRaw, yInRaw;      // Input raw pixel coordinates
     76            pswarpMapApply(&xInRaw, &yInRaw, map, x + 0.5, y + 0.5);
     77            double xIn = xInRaw - outCol0, yIn = yInRaw - outRow0; // Position on input image
     78            if (xIn < 0 || xIn >= inNumCols || yIn < 0 || yIn >= inNumRows) {
     79                continue;
     80            }
    8781
    8882            // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
    89             maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0;
     83            double imageValue, varValue; // Value of image and variance map
     84            psMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask
    9085            if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) {
    9186                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     
    9388            }
    9489
    95             int xOut = x - outCol0;     // Position on output image
    96             int yOut = y - outRow0;     // Position on output image
     90            int xOut = x - outCol0, yOut = y - outRow0; // Position on output image
    9791
    98             // not all images need be transformed
    9992            if (outImageData) {
    10093                outImageData[yOut][xOut] = imageValue;
     
    10699                outMaskData[yOut][xOut] = maskValue;
    107100            }
     101
     102            goodPixels++;
    108103        }
    109104    }
     105
    110106    args->goodPixels = goodPixels;
     107    args->xMin = xMin;
     108    args->xMax = xMax;
     109    args->yMin = yMin;
     110    args->yMax = yMax;
     111
    111112    return true;
    112113}
Note: See TracChangeset for help on using the changeset viewer.