IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 22, 2004, 10:09:04 AM (22 years ago)
Author:
desonia
Message:

moved image pixel interpolation from the psImageStats.[ch] to psImage.[ch] (logical reclassification)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImage.c

    r1205 r1261  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-07-09 21:48:07 $
     11 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-07-22 20:09:04 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    400400}
    401401
     402/*****************************************************************************
     403p_psImagePixelInterpolation(image, x, y): this routine takes as input an
     404image and coordinates (x, y) and produces as output the corresponding pixel
     405value at the those coordinates.  For fractional corrdinates (x, y), 2-D
     406linear interpolation is performed on the image.
     407 *****************************************************************************/
     408psF32 psImagePixelInterpolate(
     409    const psImage *input,
     410    float x,
     411    float y,
     412    psF32 unexposedValue,
     413    psImageInterpolateMode mode)
     414{
     415
     416    if (input == NULL) {
     417        psError(__func__,"Image can not be NULL.");
     418        return unexposedValue;
     419    }
     420
     421    #define PSIMAGE_PIXEL_INTERPOLATE_CASE(TYPE) \
     422case PS_TYPE_##TYPE: \
     423    switch (mode) { \
     424    case PS_INTERPOLATE_FLAT: \
     425        return p_psImagePixelInterpolateFLAT_##TYPE(input,x,y,unexposedValue); \
     426        break; \
     427    case PS_INTERPOLATE_BILINEAR: \
     428        return p_psImagePixelInterpolateBILINEAR_##TYPE(input,x,y,unexposedValue); \
     429        break; \
     430    default: \
     431        psError(__func__,"Unsupported interpolation mode (#%d)",mode); \
     432    } \
     433    break
     434
     435    switch (input->type.type) {
     436        PSIMAGE_PIXEL_INTERPOLATE_CASE(U8);
     437        PSIMAGE_PIXEL_INTERPOLATE_CASE(U16);
     438        PSIMAGE_PIXEL_INTERPOLATE_CASE(U32);
     439        PSIMAGE_PIXEL_INTERPOLATE_CASE(U64);
     440        PSIMAGE_PIXEL_INTERPOLATE_CASE(S8);
     441        PSIMAGE_PIXEL_INTERPOLATE_CASE(S16);
     442        PSIMAGE_PIXEL_INTERPOLATE_CASE(S32);
     443        PSIMAGE_PIXEL_INTERPOLATE_CASE(S64);
     444        PSIMAGE_PIXEL_INTERPOLATE_CASE(F32);
     445        PSIMAGE_PIXEL_INTERPOLATE_CASE(F64);
     446        PSIMAGE_PIXEL_INTERPOLATE_CASE(C32);
     447        PSIMAGE_PIXEL_INTERPOLATE_CASE(C64);
     448    default:
     449        psError(__func__,"Unsupported image datatype (%d)",input->type.type);
     450    }
     451
     452    return unexposedValue;
     453}
     454
     455#define PSIMAGE_PIXEL_INTERPOLATE_FLAT(TYPE) \
     456inline psF64 p_psImagePixelInterpolateFLAT_##TYPE(const psImage *input, \
     457        float x, \
     458        float y, \
     459        psF64 unexposedValue) \
     460{ \
     461    int intX = (int) round((psF64)(x) - 0.5); \
     462    int intY = (int) round((psF64)(y) - 0.5); \
     463    int lastX = input->numCols - 1; \
     464    int lastY = input->numRows - 1; \
     465    \
     466    if ((intX < 0) || \
     467            (intX > lastX) || \
     468            (intY < 0) || \
     469            (intY > lastY)) { \
     470        return unexposedValue; \
     471    } \
     472    \
     473    return input->data.TYPE[intY][intX]; \
     474}
     475
     476#define PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(TYPE) \
     477inline psC64 p_psImagePixelInterpolateFLAT_##TYPE(const psImage *input, \
     478        float x, \
     479        float y, \
     480        psC64 unexposedValue) \
     481{ \
     482    int intX = (int) round((psF64)(x) - 0.5); \
     483    int intY = (int) round((psF64)(y) - 0.5); \
     484    int lastX = input->numCols - 1; \
     485    int lastY = input->numRows - 1; \
     486    \
     487    if ((intX < 0) || \
     488            (intX > lastX) || \
     489            (intY < 0) || \
     490            (intY > lastY)) { \
     491        return unexposedValue; \
     492    } \
     493    \
     494    return input->data.TYPE[intY][intX]; \
     495}
     496
     497PSIMAGE_PIXEL_INTERPOLATE_FLAT(U8)
     498PSIMAGE_PIXEL_INTERPOLATE_FLAT(U16)
     499PSIMAGE_PIXEL_INTERPOLATE_FLAT(U32)
     500PSIMAGE_PIXEL_INTERPOLATE_FLAT(U64)
     501PSIMAGE_PIXEL_INTERPOLATE_FLAT(S8)
     502PSIMAGE_PIXEL_INTERPOLATE_FLAT(S16)
     503PSIMAGE_PIXEL_INTERPOLATE_FLAT(S32)
     504PSIMAGE_PIXEL_INTERPOLATE_FLAT(S64)
     505PSIMAGE_PIXEL_INTERPOLATE_FLAT(F32)
     506PSIMAGE_PIXEL_INTERPOLATE_FLAT(F64)
     507PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(C32)
     508PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(C64)
     509
     510#define PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(TYPE) \
     511inline psF64 p_psImagePixelInterpolateBILINEAR_##TYPE(const psImage *input, \
     512        float x, \
     513        float y, \
     514        psF64 unexposedValue) \
     515{ \
     516    double floorX = floor((psF64)(x) - 0.5); \
     517    double floorY = floor((psF64)(y) - 0.5); \
     518    double fracX = x - 0.5 - floorX; \
     519    double fracY = y - 0.5 - floorY; \
     520    int intFloorX = (int) floorX; \
     521    int intFloorY = (int) floorY; \
     522    int lastX = input->numCols - 1; \
     523    int lastY = input->numRows - 1; \
     524    double rx = 0.0; \
     525    psF64 pixel = 0.0; \
     526    ps##TYPE* currentRow; \
     527    ps##TYPE* nextRow; \
     528    \
     529    if ((intFloorX < 0) || \
     530            (intFloorX > lastX) || \
     531            (intFloorY < 0) || \
     532            (intFloorY > lastY)) { \
     533        return unexposedValue; \
     534    } \
     535    \
     536    currentRow = input->data.TYPE[intFloorY]; \
     537    if (intFloorY == lastY) { \
     538        pixel = currentRow[intFloorX]; \
     539        if (intFloorX < lastX) { \
     540            pixel+= fracY * ((psF64)currentRow[intFloorX+1] - \
     541                             (psF64)currentRow[intFloorX]); \
     542        } \
     543        return(pixel); \
     544    } \
     545    nextRow = input->data.TYPE[intFloorY+1]; \
     546    if (intFloorX == lastX) { \
     547        pixel = currentRow[intFloorX]; \
     548        if (intFloorY < lastY) { \
     549            pixel+= fracX * ((psF64)nextRow[intFloorX] - \
     550                             (psF64)currentRow[intFloorX]); \
     551        } \
     552        return(pixel); \
     553    } \
     554    \
     555    rx = currentRow[intFloorX] + \
     556         fracX * ((psF64)currentRow[intFloorX+1] - \
     557                  (psF64)currentRow[intFloorX]); \
     558    \
     559    pixel = rx + fracY * ((psF64)nextRow[intFloorX] + \
     560                          fracX * ((psF64)nextRow[intFloorX+1] - \
     561                                   (psF64)nextRow[intFloorX]) - rx); \
     562    \
     563    return(pixel); \
     564}
     565
     566#define PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(TYPE) \
     567inline psC64 p_psImagePixelInterpolateBILINEAR_##TYPE(const psImage *input, \
     568        float x, \
     569        float y, \
     570        psC64 unexposedValue) \
     571{ \
     572    double floorX = floor((psF64)(x) - 0.5); \
     573    double floorY = floor((psF64)(y) - 0.5); \
     574    double fracX = x - 0.5 - floorX; \
     575    double fracY = y - 0.5 - floorY; \
     576    int intFloorX = (int) floorX; \
     577    int intFloorY = (int) floorY; \
     578    int lastX = input->numCols - 1; \
     579    int lastY = input->numRows - 1; \
     580    double rx = 0.0; \
     581    psC64 pixel = 0.0; \
     582    ps##TYPE* currentRow; \
     583    ps##TYPE* nextRow; \
     584    \
     585    if ((intFloorX < 0) || \
     586            (intFloorX > lastX) || \
     587            (intFloorY < 0) || \
     588            (intFloorY > lastY)) { \
     589        return unexposedValue; \
     590    } \
     591    \
     592    currentRow = input->data.TYPE[intFloorY]; \
     593    if (intFloorY == lastY) { \
     594        pixel = currentRow[intFloorX]; \
     595        if (intFloorX < lastX) { \
     596            pixel+= fracY * (currentRow[intFloorX+1] - \
     597                             currentRow[intFloorX]); \
     598        } \
     599        return(pixel); \
     600    } \
     601    nextRow = input->data.TYPE[intFloorY+1]; \
     602    if (intFloorX == lastX) { \
     603        pixel = currentRow[intFloorX]; \
     604        if (intFloorY < lastY) { \
     605            pixel+= fracX * (nextRow[intFloorX] - \
     606                             currentRow[intFloorX]); \
     607        } \
     608        return(pixel); \
     609    } \
     610    \
     611    rx = currentRow[intFloorX] + \
     612         fracX * (currentRow[intFloorX+1] - \
     613                  currentRow[intFloorX]); \
     614    \
     615    pixel = rx + fracY * ((psF64)nextRow[intFloorX] + \
     616                          fracX * (nextRow[intFloorX+1] - \
     617                                   nextRow[intFloorX]) - rx); \
     618    \
     619    return(pixel); \
     620}
     621
     622PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(U8)
     623PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(U16)
     624PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(U32)
     625PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(U64)
     626PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(S8)
     627PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(S16)
     628PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(S32)
     629PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(S64)
     630PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(F32)
     631PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(F64)
     632PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(C32)
     633PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(C64)
     634
     635
Note: See TracChangeset for help on using the changeset viewer.