IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 9, 2006, 10:20:27 AM (20 years ago)
Author:
magnier
Message:

added test psImageShiftKernel and related p_psImageShiftKernel_F32; added PS_INTERPOLATE_GAUSS

File:
1 edited

Legend:

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

    r9865 r9927  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-11-06 02:02:59 $
     12 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-11-09 20:20:27 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    594594}
    595595
     596// XXX this function seems to work (except for edge pixels and masked pixels
     597// but the function below does not define the right 3x3 kernels.  look this
     598// up
     599psImage *p_psImageShiftKernel_F32(
     600    psImage *out,
     601    const psImage *input,
     602    const psImage *kernel)
     603{
     604
     605    PS_ASSERT_IMAGE_NON_NULL(input, NULL);
     606    PS_ASSERT_IMAGE_NON_NULL(kernel, NULL);
     607
     608    if ((kernel->numCols % 2 == 0) || (kernel->numRows % 2 == 0)) {
     609        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     610                _("kernel must have odd dimensions"));
     611        return NULL;
     612    }
     613    int Xk = (kernel->numCols - 1) / 2;
     614    int Yk = (kernel->numRows - 1) / 2;
     615
     616    int outRows = input->numRows;
     617    int outCols = input->numCols;
     618    out = psImageRecycle(out, outCols, outRows, input->type.type);
     619    psImageInit (out, 0.0);
     620
     621    // need to handle the edge cases...
     622    for (int row = 1; row < outRows-1; row++) {
     623        psF32 *outRow = out->data.F32[row];
     624        psF32 **inValue = input->data.F32;
     625        for (int col = 1; col < outCols-1; col++) {
     626            double value = 0;
     627            double norm = 0;
     628            psF32 **kernValue = kernel->data.F32;
     629            for (int yi = -Yk; yi <= Yk; yi++) {
     630                for (int xi = -Xk; xi <= Xk; xi++) {
     631                    value += inValue[row+yi][col+xi]*kernValue[yi+Yk][xi+Xk];
     632                    norm += kernValue[yi+Yk][xi+Xk];
     633                }
     634            }
     635            // include the mask tests and divide-by-zero test
     636            outRow[col] = value / norm;
     637        }
     638    }
     639
     640    return (out);
     641}
     642
     643// XXX fix the definition of the interpolation kernels and add integer shifts
     644psImage *psImageShiftKernel (
     645    psImage *out,
     646    const psImage *input,
     647    float dx, float dy, psImageInterpolateMode mode)
     648{
     649
     650    psImage *kernel = NULL;
     651
     652    switch (mode) {
     653    case PS_INTERPOLATE_BICUBE:
     654        kernel = psImageAlloc (3, 3, PS_TYPE_F32);
     655        for (int iy = -1; iy <= +1; iy++) {
     656            for (int ix = -1; ix <= +1; ix++) {
     657                kernel->data.F32[iy+1][ix+1] = 5 - 3*PS_SQR(ix+dx) - 3*PS_SQR(iy+dy);
     658            }
     659        }
     660        out = p_psImageShiftKernel_F32 (out, input, kernel);
     661        break;
     662
     663    case PS_INTERPOLATE_GAUSS:
     664        kernel = psImageAlloc (3, 3, PS_TYPE_F32);
     665        for (int iy = -1; iy <= +1; iy++) {
     666            for (int ix = -1; ix <= +1; ix++) {
     667                kernel->data.F32[iy+1][ix+1] = exp(-0.5*PS_SQR(ix+dx) -0.5*PS_SQR(iy+dy));
     668            }
     669        }
     670        out = p_psImageShiftKernel_F32 (out, input, kernel);
     671        break;
     672
     673    default:
     674        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     675                _("shift kernel for %d not defined"), mode);
     676        return NULL;
     677    }
     678    psFree (kernel);
     679    return (out);
     680}
     681
    596682psImage* psImageShift(psImage* out,
    597683                      const psImage* input,
Note: See TracChangeset for help on using the changeset viewer.