IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12744


Ignore:
Timestamp:
Apr 4, 2007, 12:54:56 PM (19 years ago)
Author:
Paul Price
Message:

Updating following API change to psImagePixelInterpolate

Location:
trunk
Files:
4 edited

Legend:

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

    r10958 r12744  
    33bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config) {
    44
    5     // XXX this implementation currently ignores the use of the region 
     5    // XXX this implementation currently ignores the use of the region
    66    psImage *region = NULL;
    77    pmCell *cell = NULL;
     
    1313    int outNy = output->image->numRows;
    1414
    15     psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
    16     psPlane *outPix = psPlaneAlloc();   // Coordinates on the output detector
     15    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
     16    psPlane *outPix = psPlaneAlloc();   // Coordinates on the output detector
    1717
    18     psPlane *FP = psPlaneAlloc();       // Coordinates on the focal plane
    19     psPlane *TP = psPlaneAlloc();       // Coordinates on the tangent plane
    20     psSphere *sky = psSphereAlloc();    // Coordinates on the sky
     18    psPlane *FP = psPlaneAlloc();       // Coordinates on the focal plane
     19    psPlane *TP = psPlaneAlloc();       // Coordinates on the tangent plane
     20    psSphere *sky = psSphereAlloc();    // Coordinates on the sky
    2121
    2222    cell = input->parent;
     
    3131    psImage *inImage = input->image;
    3232
     33    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage,
     34                                                                       NULL, NULL, 0, NAN, NAN, 0, 0, 0.0);
     35
    3336    // Iterate over the output image pixels
    3437    for (int y = 0; y < outNy; y++) {
    35         for (int x = 0; x < outNx; x++) {
    36             // Only transform those pixels requested
    37             if (region && region->data.U8[y][x]) continue;
     38        for (int x = 0; x < outNx; x++) {
     39            // Only transform those pixels requested
     40            if (region && region->data.U8[y][x]) continue;
    3841
    39             // XXX double check this 1/2 pixel offset
    40             outPix->x = (double)x + 0.5;
    41             outPix->y = (double)y + 0.5;
     42            // XXX double check this 1/2 pixel offset
     43            outPix->x = (double)x + 0.5;
     44            outPix->y = (double)y + 0.5;
    4245
    43             psPlaneTransformApply(FP, chipOutput->toFPA, outPix);
    44             psPlaneTransformApply (TP, fpaOutput->toTPA, FP);
    45             psDeproject (sky, TP, fpaOutput->toSky);
    46                
    47             psProject (TP, sky, fpaInput->toSky);
    48             psPlaneTransformApply (FP, fpaInput->fromTPA, TP);
    49             psPlaneTransformApply (inPix, chipInput->fromFPA, FP);
     46            psPlaneTransformApply(FP, chipOutput->toFPA, outPix);
     47            psPlaneTransformApply (TP, fpaOutput->toTPA, FP);
     48            psDeproject (sky, TP, fpaOutput->toSky);
    5049
    51             // XXX get interpolation method from the recipe
    52             outData[y][x] = (psF32)psImagePixelInterpolate(inImage, inPix->x, inPix->y, NULL, 1, NAN, PS_INTERPOLATE_BILINEAR);
    53             // outData[y][x] = (psF32)psImagePixelInterpolate(inImage, inPix->x, inPix->y, mask, 1, NAN, PS_INTERPOLATE_BILINEAR);
    54             // modify zero and scale?
    55         }
     50            psProject (TP, sky, fpaInput->toSky);
     51            psPlaneTransformApply (FP, fpaInput->fromTPA, TP);
     52            psPlaneTransformApply (inPix, chipInput->fromFPA, FP);
     53
     54            // XXX get interpolation method from the recipe
     55            double value;
     56            if (!psImageInterpolate(&value, NULL, NULL, inPix->x, inPix->y, interp)) {
     57                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     58                psFree(interp);
     59                psFree(inPix);
     60                psFree(outPix);
     61                psFree(FP);
     62                psFree(TP);
     63                psFree(sky);
     64                return false;
     65            }
     66
     67            outData[y][x] = value;
     68            // modify zero and scale?
     69        }
    5670    }
    57 
    58     psFree (inPix);
    59     psFree (outPix);
    60     psFree (FP);
    61     psFree (TP);
    62     psFree (sky);
     71    psFree(interp);
     72    psFree(inPix);
     73    psFree(outPix);
     74    psFree(FP);
     75    psFree(TP);
     76    psFree(sky);
    6377
    6478    return true;
    6579}
    66 
    67 # if (0)
    68             if (error) {
    69                 // Error is actually the variance
    70                 outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,
    71                                                                                         detector->x,
    72                                                                                         detector->y,
    73                                                                                         mask, 1, NAN);
    74             }
    75             if (error) {
    76                 outError->data.F32[y][x] = outError->data.F32[y][x] / SQUARE(scale);
    77             }
    78 # endif
  • trunk/pswarp/src/pswarpTransformReadout_Opt.c

    r12528 r12744  
    11# include "pswarp.h"
    2 psImageInterpolateMode psImageInterpolateModeFromString (char *name);
    32
    43// NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
     
    1110    psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE;
    1211
    13     // XXX this implementation currently ignores the use of the region 
     12    // XXX this implementation currently ignores the use of the region
    1413    psImage *region = NULL;
    1514
     
    1918    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
    2019    if (!recipe) {
    21         psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
    22         return false;
     20        psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
     21        return false;
    2322    }
    24    
     23
    2524    int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX");
    2625    if (!status) nGridX = 128;
     
    3029    char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE");
    3130    if (!name) {
    32         interpolationMode = PS_INTERPOLATE_BILINEAR;
    33         psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n");
     31        interpolationMode = PS_INTERPOLATE_BILINEAR;
     32        psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n");
    3433    } else {
    35         interpolationMode = psImageInterpolateModeFromString (name);
    36         if (interpolationMode == PS_INTERPOLATE_NONE) {
    37             interpolationMode = PS_INTERPOLATE_BILINEAR;
    38             psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);
    39         }
     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        }
    4039    }
    4140
    42     psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
     41    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
    4342    psImage *inImage = input->image;
    4443    psF32 **outData = output->image->data.F32;
     
    6564    psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError);
    6665
    67     pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 
     66    pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY);
    6867    nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
    6968    map = grid->maps[gridX][gridY];
     
    7776    nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
    7877
     78    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage,
     79                                                                       NULL, NULL, 0, NAN, NAN, 0, 0, 0.0);
     80
    7981    // Iterate over the output image pixels (parent frame)
    8082    for (int y = minY; y < maxY; y++) {
    81         if (y >= nextGridY) {
    82             gridY ++;
    83             nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
    84             map = grid->maps[gridX][gridY];
    85         }
     83        if (y >= nextGridY) {
     84            gridY ++;
     85            nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
     86            map = grid->maps[gridX][gridY];
     87        }
    8688
    87         gridX = gridXo;
    88         nextGridX = nextGridXo;
    89         map = grid->maps[gridX][gridY];
    90         for (int x = minX; x < maxX; x++) {
    91             if (x >= nextGridX) {
    92                 gridX ++;
    93                 nextGridX = pswarpMapGridNextGrid_X (grid, gridX);
    94                 map = grid->maps[gridX][gridY];
    95             }
     89        gridX = gridXo;
     90        nextGridX = nextGridXo;
     91        map = grid->maps[gridX][gridY];
     92        for (int x = minX; x < maxX; x++) {
     93            if (x >= nextGridX) {
     94                gridX ++;
     95                nextGridX = pswarpMapGridNextGrid_X (grid, gridX);
     96                map = grid->maps[gridX][gridY];
     97            }
    9698
    97             // Only transform those pixels requested
    98             if (region && region->data.U8[y][x]) continue;
     99            // Only transform those pixels requested
     100            if (region && region->data.U8[y][x]) continue;
    99101
    100             // pswarpMapApply converts the output coordinate (x,y) to the input coordinate.
    101             // both are in the parent frames of the input and output images.
    102             pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5);
     102            // pswarpMapApply converts the output coordinate (x,y) to the input coordinate.
     103            // both are in the parent frames of the input and output images.
     104            pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5);
    103105
    104             if (inPix->x - inCol0 < 0) continue;
    105             if (inPix->x - inCol0 >= inImage->numCols) continue;
    106             if (inPix->y - inRow0 < 0) continue;
    107             if (inPix->y - inRow0 >= inImage->numRows) continue;
     106            if (inPix->x - inCol0 < 0) continue;
     107            if (inPix->x - inCol0 >= inImage->numCols) continue;
     108            if (inPix->y - inRow0 < 0) continue;
     109            if (inPix->y - inRow0 >= inImage->numRows) continue;
    108110
    109             // XXX include mask
    110             // XXX apply scale and offset?
    111             // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
    112             outData[y-outRow0][x-outCol0] = (psF32)psImagePixelInterpolate(inImage, inPix->x - inCol0, inPix->y - inRow0, NULL, 1, NAN, interpolationMode);
    113         }
     111            // XXX include mask
     112            // XXX apply scale and offset?
     113            // 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)) {
     116                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     117                psFree(interp);
     118                psFree (inPix);
     119                psFree (grid);
     120                return false;
     121            }
     122            outData[y-outRow0][x-outCol0] = value;
     123        }
    114124    }
    115125
     126    psFree(interp);
    116127    psFree (inPix);
    117128    psFree (grid);
  • trunk/stac/src/stacRejection.c

    r9740 r12744  
    111111#endif
    112112
     113        psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR,
     114                                                                           reject, NULL, NULL, 0, 0.0, 0.0,
     115                                                                           0, 0, 0.0);
     116
    113117        // Transform the mask
    114118        // Optimisation option is to only transform the pixels that have been rejected in the output,
     
    125129                    inCoords->y = (double)y + 0.5;
    126130                    (void)psPlaneTransformApply(outCoords, map, inCoords);
    127                     float maskVal = (float)psImagePixelInterpolate(reject, outCoords->x, outCoords->y,
    128                                                                    NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR);
     131                    double maskVal;
     132                    if (!psImageInterpolate(&maskVal, NULL, NULL, outCoords->x, outCoords->y, interp)) {
     133                        psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     134                        psFree(grads);
     135                        psFree(gradsMask);
     136                        psFree(inCoords);
     137                        psFree(outCoords);
     138                        return NULL;
     139                    }
     140
    129141#ifdef TESTING
    130142                    rejmap->data.F32[y][x] = maskVal;
  • trunk/stac/src/stacTransform.c

    r9740 r12744  
    193193        }
    194194
     195        psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR,
     196                                                                           image, error, mask, 1, NAN, NAN,
     197                                                                           1, 0, 0.0);
     198
    195199        // Iterate over the output image pixels
    196200        for (int y = 0; y < outny; y++) {
     
    204208
    205209                    // Change PS_INTERPOLATE_BILINEAR to best available technique.
    206                     outImage->data.F32[y][x] = (psF32)psImagePixelInterpolate(image, detector->x,
    207                                                                               detector->y, mask, 1, NAN,
    208                                                                               PS_INTERPOLATE_BILINEAR);
     210                    double imageValue, varianceValue;
     211                    if (!psImageInterpolate(&imageValue, &varianceValue, NULL,
     212                                            detector->x, detector->y, interp)) {
     213                        psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     214                        psFree(interp);
     215                        psFree(detector);
     216                        psFree(sky);
     217                        return false;
     218                    }
     219                    outImage->data.F32[y][x] = imageValue;
     220
    209221                    if (error) {
    210222                        // Error is actually the variance
    211                         outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,
    212                                                                                                 detector->x,
    213                                                                                                 detector->y,
    214                                                                                                 mask, 1, NAN);
     223                        outError->data.F32[y][x] = varianceValue;
    215224                    }
    216225
     
    224233            }
    225234        } // Iterating over output pixels
     235        psFree(interp);
    226236
    227237    } // Iterating over images
Note: See TracChangeset for help on using the changeset viewer.