IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31446


Ignore:
Timestamp:
May 5, 2011, 10:37:54 AM (15 years ago)
Author:
eugene
Message:

compile-time option for separable (but unthreaded) bilinear interpolation (which is faster?); correct psImageMaskCircle for 0.5 pixel offset

Location:
trunk/psLib/src/imageops
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageGeomManip.c

    r23989 r31446  
    702702    } \
    703703    /* note: output(i,j) = input(i+0.5-dx,j+0.5-dy) */ \
    704     /* positive dx,dy moves pixel i-dx,j-dy to i,y */ \
     704    /* positive dx,dy moves pixel i-dx,j-dy to i,j */ \
    705705    /* also: pixel center is 0.5,0.5 */ \
    706706    for (int row = 0; row < numRows; row++) { \
  • trunk/psLib/src/imageops/psImageInterpolate.c

    r28667 r31446  
    3131#include "psImageConvolve.h"
    3232
     33# define IS_BILIN_SEPARABLE 0
     34
    3335#include "psImageInterpolate.h"
    3436
     
    4850};
    4951
     52# if (IS_BILIN_SEPARABLE)
    5053/// Generate a linear interpolation kernel
    5154static inline void interpolationKernelBilinear(psF32 *kernel, // Kernel vector to populate
     
    5659    kernel[1] = frac;
    5760}
     61# else
     62/// Generate a linear interpolation kernel
     63static inline void interpolationKernelBilinear(
     64    psF32 kernel[kernelSizes[PS_INTERPOLATE_BILINEAR]][kernelSizes[PS_INTERPOLATE_BILINEAR]], // Kernel
     65    float xFrac, float yFrac // Fraction of pixel
     66    )
     67{
     68    // (xF*yF, (1-xF)(1-yF) = 1 - xF - yF + xFyF
     69
     70    kernel[0][0] = 1.0 - xFrac - yFrac + xFrac*yFrac;
     71    kernel[1][0] = yFrac - xFrac*yFrac;
     72    kernel[0][1] = xFrac - xFrac*yFrac;
     73    kernel[1][1] = xFrac*yFrac;
     74}
     75# endif
    5876
    5977#if 0
     
    173191        // Nothing to pre-compute
    174192        break;
     193# if (IS_BILIN_SEPARABLE)
    175194      case PS_INTERPOLATE_BILINEAR:
    176195        interpolationKernelBilinear(kernel, frac);
    177196        break;
     197# endif
    178198      case PS_INTERPOLATE_GAUSS:
    179199        interpolationKernelGauss(kernel, kernelSizes[mode], 0.5, frac);
     
    184204        interpolationKernelLanczos(kernel, kernelSizes[mode], frac);
    185205        break;
     206# if (!IS_BILIN_SEPARABLE)
     207      case PS_INTERPOLATE_BILINEAR:
     208# endif
    186209      case PS_INTERPOLATE_BIQUADRATIC:  // 2D kernel
    187210      default:
     
    234257
    235258    switch (mode) {
     259# if (IS_BILIN_SEPARABLE)
    236260      case PS_INTERPOLATE_BILINEAR:
     261# endif
    237262      case PS_INTERPOLATE_GAUSS:
    238263      case PS_INTERPOLATE_LANCZOS2:
     
    258283        }
    259284        break;
     285# if (!IS_BILIN_SEPARABLE)
     286      case PS_INTERPOLATE_BILINEAR:
     287# endif
    260288      case PS_INTERPOLATE_BIQUADRATIC:
    261289        // 2D kernel, would cost too much memory to pre-calculate
     
    360388    int xCentral = floor((X) - 0.5), yCentral = floor((Y) - 0.5); /* Central pixel */ \
    361389    float xFrac = (X) - xCentral - 0.5, yFrac = (Y) - yCentral - 0.5; /* Fraction of pixel */ \
     390    bool xExact = fabsf(xFrac) < FLT_EPSILON, yExact = fabsf(yFrac) < FLT_EPSILON; /* Are shifts exact? */ \
     391
     392// Set up the kernel parameters; defines some useful values
     393// EAM : I'm unsure of the right answer here
     394#define INTERPOLATE_SETUP_EAM(X, Y)                              \
     395    int xCentral = floor((X)), yCentral = floor((Y)); /* Central pixel */ \
     396    float xFrac = (X) - xCentral, yFrac = (Y) - yCentral; /* Fraction of pixel */ \
    362397    bool xExact = fabsf(xFrac) < FLT_EPSILON, yExact = fabsf(yFrac) < FLT_EPSILON; /* Are shifts exact? */ \
    363398
     
    722757}
    723758
    724 // Interpolation engine for (separable) interpolation kernels
     759// Interpolation engine for (non-separable) interpolation kernels
    725760static psImageInterpolateStatus interpolateKernel(double *imageValue, double *varianceValue,
    726761                                                  psImageMaskType *maskValue, float x, float y,
     
    747782    // Get the appropriate kernels
    748783    psF32 kernel[size][size];
     784
     785# if (IS_BILIN_SEPARABLE)
    749786    psAssert(mode == PS_INTERPOLATE_BIQUADRATIC, "Mode is %x", mode);
    750787    interpolationKernelBiquadratic(kernel, xFrac, yFrac);
     788# else
     789    psAssert((mode == PS_INTERPOLATE_BIQUADRATIC) || (mode == PS_INTERPOLATE_BILINEAR), "Mode is %x", mode);
     790    if (mode == PS_INTERPOLATE_BIQUADRATIC) {
     791        interpolationKernelBiquadratic(kernel, xFrac, yFrac);
     792    } else {
     793        interpolationKernelBilinear(kernel, xFrac, yFrac);
     794    }
     795# endif
     796
     797# if (0)
     798    for (int i = 0; i < size; i++) {
     799        for (int j = 0; j < size; j++) {
     800            fprintf (stderr, "%f ", kernel[i][j]);
     801        }
     802        fprintf (stderr, "\n");
     803    }
     804# endif
    751805
    752806    float sumKernel = 0.0;              // Sum of the kernel
     
    908962        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
    909963      case PS_INTERPOLATE_BILINEAR:
     964# if (!IS_BILIN_SEPARABLE)
     965        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
     966# endif
    910967      case PS_INTERPOLATE_GAUSS:
    911968      case PS_INTERPOLATE_LANCZOS2:
  • trunk/psLib/src/imageops/psImageMaskOps.c

    r25753 r31446  
    146146    for (int iy = 0; iy < image->numRows; iy++) { \
    147147        for (int ix = 0; ix < image->numCols; ix++) { \
    148             dx = ix + image->col0 - x; \
    149             dy = iy + image->row0 - y; \
     148            dx = ix + 0.5 + image->col0 - x; \
     149            dy = iy + 0.5 + image->row0 - y; \
    150150            r2 = PS_SQR(dx) + PS_SQR(dy); \
    151151            if (r2 <= R2) { \
     
    197197    for (int iy = 0; iy < image->numRows; iy++) { \
    198198        for (int ix = 0; ix < image->numCols; ix++) { \
    199             dx = ix + image->col0 - x; \
    200             dy = iy + image->row0 - y; \
     199            dx = ix + 0.5 + image->col0 - x; \
     200            dy = iy + 0.5 + image->row0 - y; \
    201201            r2 = PS_SQR(dx) + PS_SQR(dy); \
    202202            if (r2 > R2) { \
Note: See TracChangeset for help on using the changeset viewer.