IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 5, 2007, 5:38:16 PM (19 years ago)
Author:
Paul Price
Message:

Adding variance and mask output.

File:
1 edited

Legend:

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

    r12744 r12771  
    22
    33// NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
    4 bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) {
    5 
    6     bool status;
    7     int minX, minY, maxX, maxY;
    8     int gridXo, gridX, gridY, nextGridXo, nextGridX, nextGridY;
    9     pswarpMap *map = NULL;
    10     psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE;
    11 
     4bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config)
     5{
    126    // XXX this implementation currently ignores the use of the region
    137    psImage *region = NULL;
     
    159    psTimerStart ("warp");
    1610
    17     // select the current recipe
    18     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
    19     if (!recipe) {
    20         psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
    21         return false;
    22     }
    23 
    24     int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX");
    25     if (!status) nGridX = 128;
    26     int nGridY = psMetadataLookupS32 (&status, recipe, "GRID.NY");
    27     if (!status) nGridY = 128;
    28 
    29     char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE");
    30     if (!name) {
    31         interpolationMode = PS_INTERPOLATE_BILINEAR;
    32         psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n");
    33     } else {
    34         interpolationMode = psImageInterpolateModeFromString (name);
    35         if (interpolationMode == PS_INTERPOLATE_NONE) {
    36             interpolationMode = PS_INTERPOLATE_BILINEAR;
    37             psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);
    38         }
    39     }
    40 
    41     psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
    42     psImage *inImage = input->image;
    43     psF32 **outData = output->image->data.F32;
     11    // Get grid size
     12    int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX");
     13    int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY");
     14    psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments,
     15                                                                   "INTERPOLATION.MODE");
     16    psMaskType maskIn = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for input data
     17    psMaskType maskPoor = psMetadataLookupU8(NULL, config->arguments, "MASK.POOR"); // Mask for "poor" data
     18    psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for bad data
     19    float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor"
    4420
    4521    // we need to apply the offset to convert parent coordinates to child coordinates for
     
    5430
    5531    // find the output pixel range
     32    int minX, minY, maxX, maxY;
    5633    pswarpMatchRange (&minX, &minY, &maxX, &maxY, input, output);
    5734
     
    6441    psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError);
    6542
     43    int gridX, gridY, nextGridX, nextGridY;
    6644    pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY);
    6745    nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
    68     map = grid->maps[gridX][gridY];
     46    pswarpMap *map = grid->maps[gridX][gridY];
    6947
    7048    assert ((int)(minX - outCol0) >= 0);
     
    7351    assert ((int)(maxY - outRow0) <= output->image->numRows);
    7452
    75     gridXo = gridX;
    76     nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
     53    int gridXo = gridX;
     54    int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
    7755
    78     psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage,
    79                                                                        NULL, NULL, 0, NAN, NAN, 0, 0, 0.0);
     56    psImage *inImage = input->image;    // Input image
     57    psImage *inVar   = input->weight;   // Input weight map
     58    psImage *inMask  = input->mask;     // Input mask
     59
     60    // Interpolation options
     61    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(interpolationMode, inImage,
     62                                                                       inVar, inMask, maskIn, NAN, NAN,
     63                                                                       maskPoor, maskBad, poorFrac);
     64
     65    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
     66    psF32 **outImageData = output->image->data.F32; // Output image pixels
     67    psF32 **outVarData;                 // Output variance pixels
     68    psMaskType **outMaskData;           // Output mask pixels
     69    if (inVar) {
     70        if (!output->weight) {
     71            output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32);
     72        }
     73        outVarData = output->weight->data.F32;
     74    }
     75    if (inMask) {
     76        if (!output->mask) {
     77            output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK);
     78        }
     79        outMaskData = output->mask->data.PS_TYPE_MASK_DATA;
     80    }
    8081
    8182    // Iterate over the output image pixels (parent frame)
     
    112113            // XXX apply scale and offset?
    113114            // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
    114             double value;
    115             if (!psImageInterpolate(&value, NULL, NULL, inPix->x - inCol0, inPix->y - inRow0, interp)) {
     115            double imageValue, varValue;
     116            psMaskType maskValue;
     117            if (!psImageInterpolate(&imageValue, &varValue, &maskValue,
     118                                    inPix->x - inCol0, inPix->y - inRow0, interp)) {
    116119                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
    117120                psFree(interp);
     
    120123                return false;
    121124            }
    122             outData[y-outRow0][x-outCol0] = value;
     125            outImageData[y-outRow0][x-outCol0] = imageValue;
     126            if (inVar) {
     127                outVarData[y-outRow0][x-outCol0] = varValue;
     128            }
     129            if (inMask) {
     130                outMaskData[y-outRow0][x-outCol0] = maskValue;
     131            }
    123132        }
    124133    }
Note: See TracChangeset for help on using the changeset viewer.