IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1076


Ignore:
Timestamp:
Jun 23, 2004, 3:38:45 PM (22 years ago)
Author:
gusciora
Message:

Added interpolation routines.

Location:
trunk/psLib/src
Files:
2 edited

Legend:

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

    r1073 r1076  
    164164float *p_psCalcScaleFactorsEval(int n)
    165165{
     166    int i = 0;
     167    float tmp = 0.0;
    166168    return p_psCalcScaleFactorsFit(n);
    167     float tmp = 0.0;
    168     int i = 0;
    169     //    float tmp = 0.0;
     169
     170    printf("Should not get here\n");
    170171    float *scalingFactors = (float *) psAlloc(n * sizeof(float));
    171172    for (i=0;i<n;i++) {
    172173        //          scalingFactors[i] = ((2.0 * (float) i) / ((float) (n-1))) - 1.0;
    173         tmp = (float) (i + 1);
     174        tmp = (float) (n - i);
    174175        tmp = (M_PI * (tmp - 0.5)) / ((float) n);
    175176        scalingFactors[i] = cos(tmp);
     
    224225                     psPolynomial2D *coeffs)
    225226{
    226     int k = 0;
    227     int l = 0;
    228227    int x = 0;
    229228    int y = 0;
     
    245244
    246245    // We scale the pixel positions to values between -1.0 and 1.0
    247     cScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
    248     rScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
     246    rScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
     247    cScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
    249248
    250249    // Determine how many Chebyshev polynomials are needed, then create them.
     
    264263
    265264            }
    266             printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);
     265            //printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);
    267266        }
    268267    }
     
    282281    }
    283282
    284     // NOTE: Check the math on this at a later date.
    285     //    coeffs->coeff[0][0] = sums[0][0] / ((float) (coeffs->nX * coeffs->nY));
    286     //    for (i=0;i<coeffs->nX;i++) {
    287     //        coeffs->coeff[i][0] = ((sums[i][0] * 2.0) /
    288     //                               ((float) (coeffs->nX * coeffs->nY))) -
    289     //                              coeffs->coeff[0][0];
    290     //    }
    291     //    for (j=0;j<coeffs->nY;j++) {
    292     //        coeffs->coeff[0][j] =
    293     //            ((sums[0][j] * 2.0) /
    294     //             ((float) (coeffs->nX * coeffs->nY))) -
    295     //            coeffs->coeff[0][0];
    296     //    }
    297 
    298283    for (i=0;i<coeffs->nX;i++) {
    299284        for (j=0;j<coeffs->nY;j++) {
    300285            coeffs->coeff[i][j] = sums[i][j];
    301             coeffs->coeff[i][j]/= ((float) coeffs->nX) * ((float) coeffs->nY);
     286            coeffs->coeff[i][j]/= (float) (input->numRows * input->numCols);
     287
    302288            if ((i != 0) && (j != 0)) {
    303289                coeffs->coeff[i][j]*= 4.0;
     
    307293                coeffs->coeff[i][j]*= 2.0;
    308294            }
    309 
    310             //            coeffs->coeff[i][j] =
    311             //                ((sums[i][0] * 4.0) / ((float) (coeffs->nX * coeffs->nY))) -
    312             //                (coeffs->coeff[0][0] +
    313             //                 coeffs->coeff[i][0] +
    314             //                 coeffs->coeff[0][j]);
    315         }
    316     }
    317 
    318     for (k=0;k<coeffs->nX;k++) {
    319         for (l=0;l<coeffs->nY;l++) {
    320             tmp = 0.0;
    321             for (i=0;i<coeffs->nX;i++) {
    322                 for (j=0;j<coeffs->nY;j++) {
    323                     for (x=0;x<input->numRows;x++) {
    324                         for (y=0;y<input->numCols;y++) {
    325                             tmp+= (coeffs->coeff[i][j] *
    326                                    psEvalPolynomial1D(rScalingFactors[x], chebPolys[i]) *
    327                                    psEvalPolynomial1D(rScalingFactors[y], chebPolys[j]) *
    328                                    psEvalPolynomial1D(rScalingFactors[x], chebPolys[k]) *
    329                                    psEvalPolynomial1D(rScalingFactors[y], chebPolys[l]));
    330 
    331                         }
    332                     }
    333                 }
    334             }
    335         }
    336     }
    337 
     295        }
     296    }
    338297
    339298    // Free the Chebyshev polynomials that were created in this routine.
     
    385344
    386345    // We scale the pixel positions to values between -1.0 and 1.0
    387     cScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
    388     rScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
     346    rScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
     347    cScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
    389348
    390349    // Determine how many Chebyshev polynomials are needed, then create them.
     
    427386    return(0);
    428387}
     388
     389/*****************************************************************************
     390p_psImagePixelInterpolation(image, x, y): this routine takes as input an
     391image and coordinates (x, y) and produces as output the corresponding pixel
     392value at the those coordinates.  For fractional corrdinates (x, y), 2-D
     393linear interpolation is performed on the image.
     394 *****************************************************************************/
     395float psImagePixelInterpolation(psImage *input,
     396                                float x,
     397                                float y)
     398{
     399    float floorX = 0.0;
     400    float floorY = 0.0;
     401    float fracX = 0.0;
     402    float fracY = 0.0;
     403    int intFloorX = 0;
     404    int intFloorY = 0;
     405    float x1 = 0.0;
     406    float x2 = 0.0;
     407    float pixel = 0.0;
     408
     409    if ((x < 0.0) ||
     410            (x > ((float) input->numRows-1)) ||
     411            (y < 0.0) ||
     412            (y > ((float) input->numCols-1))) {
     413        psAbort(__func__,
     414                "Fractional coordinates (%f %f) outside image range.", x, y);
     415    }
     416
     417    floorX = floorf(x);
     418    intFloorX = (int) floorX;
     419    fracX = x - floorX;
     420
     421    floorY = floorf(y);
     422    intFloorY = (int) floorY;
     423    fracY = y - floorY;
     424
     425    if (intFloorX == (input->numRows-1)) {
     426        pixel = input->data.F32[intFloorX][intFloorY];
     427        if (intFloorY < (input->numCols-1)) {
     428            pixel+= fracY * (input->data.F32[intFloorX][intFloorY+1] -
     429                             input->data.F32[intFloorX][intFloorY]);
     430        }
     431        return(pixel);
     432    } else if (intFloorX == (input->numCols-1)) {
     433        if (intFloorX < (input->numRows-1)) {
     434            pixel+= fracX * (input->data.F32[intFloorX+1][intFloorY] -
     435                             input->data.F32[intFloorX][intFloorY]);
     436        }
     437        return(pixel);
     438    }
     439
     440
     441    x1 = input->data.F32[intFloorX][intFloorY];
     442    x1+= fracY * (input->data.F32[intFloorX][intFloorY+1] -
     443                  input->data.F32[intFloorX][intFloorY]);
     444
     445    x2 = input->data.F32[intFloorX+1][intFloorY];
     446    x2+= fracY * (input->data.F32[intFloorX+1][intFloorY+1] -
     447                  input->data.F32[intFloorX+1][intFloorY]);
     448    pixel = x1;
     449    pixel+= fracX * (x2 - x1);
     450
     451    return(pixel);
     452}
  • trunk/psLib/src/imageops/psImageStats.c

    r1073 r1076  
    164164float *p_psCalcScaleFactorsEval(int n)
    165165{
     166    int i = 0;
     167    float tmp = 0.0;
    166168    return p_psCalcScaleFactorsFit(n);
    167     float tmp = 0.0;
    168     int i = 0;
    169     //    float tmp = 0.0;
     169
     170    printf("Should not get here\n");
    170171    float *scalingFactors = (float *) psAlloc(n * sizeof(float));
    171172    for (i=0;i<n;i++) {
    172173        //          scalingFactors[i] = ((2.0 * (float) i) / ((float) (n-1))) - 1.0;
    173         tmp = (float) (i + 1);
     174        tmp = (float) (n - i);
    174175        tmp = (M_PI * (tmp - 0.5)) / ((float) n);
    175176        scalingFactors[i] = cos(tmp);
     
    224225                     psPolynomial2D *coeffs)
    225226{
    226     int k = 0;
    227     int l = 0;
    228227    int x = 0;
    229228    int y = 0;
     
    245244
    246245    // We scale the pixel positions to values between -1.0 and 1.0
    247     cScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
    248     rScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
     246    rScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
     247    cScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
    249248
    250249    // Determine how many Chebyshev polynomials are needed, then create them.
     
    264263
    265264            }
    266             printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);
     265            //printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);
    267266        }
    268267    }
     
    282281    }
    283282
    284     // NOTE: Check the math on this at a later date.
    285     //    coeffs->coeff[0][0] = sums[0][0] / ((float) (coeffs->nX * coeffs->nY));
    286     //    for (i=0;i<coeffs->nX;i++) {
    287     //        coeffs->coeff[i][0] = ((sums[i][0] * 2.0) /
    288     //                               ((float) (coeffs->nX * coeffs->nY))) -
    289     //                              coeffs->coeff[0][0];
    290     //    }
    291     //    for (j=0;j<coeffs->nY;j++) {
    292     //        coeffs->coeff[0][j] =
    293     //            ((sums[0][j] * 2.0) /
    294     //             ((float) (coeffs->nX * coeffs->nY))) -
    295     //            coeffs->coeff[0][0];
    296     //    }
    297 
    298283    for (i=0;i<coeffs->nX;i++) {
    299284        for (j=0;j<coeffs->nY;j++) {
    300285            coeffs->coeff[i][j] = sums[i][j];
    301             coeffs->coeff[i][j]/= ((float) coeffs->nX) * ((float) coeffs->nY);
     286            coeffs->coeff[i][j]/= (float) (input->numRows * input->numCols);
     287
    302288            if ((i != 0) && (j != 0)) {
    303289                coeffs->coeff[i][j]*= 4.0;
     
    307293                coeffs->coeff[i][j]*= 2.0;
    308294            }
    309 
    310             //            coeffs->coeff[i][j] =
    311             //                ((sums[i][0] * 4.0) / ((float) (coeffs->nX * coeffs->nY))) -
    312             //                (coeffs->coeff[0][0] +
    313             //                 coeffs->coeff[i][0] +
    314             //                 coeffs->coeff[0][j]);
    315         }
    316     }
    317 
    318     for (k=0;k<coeffs->nX;k++) {
    319         for (l=0;l<coeffs->nY;l++) {
    320             tmp = 0.0;
    321             for (i=0;i<coeffs->nX;i++) {
    322                 for (j=0;j<coeffs->nY;j++) {
    323                     for (x=0;x<input->numRows;x++) {
    324                         for (y=0;y<input->numCols;y++) {
    325                             tmp+= (coeffs->coeff[i][j] *
    326                                    psEvalPolynomial1D(rScalingFactors[x], chebPolys[i]) *
    327                                    psEvalPolynomial1D(rScalingFactors[y], chebPolys[j]) *
    328                                    psEvalPolynomial1D(rScalingFactors[x], chebPolys[k]) *
    329                                    psEvalPolynomial1D(rScalingFactors[y], chebPolys[l]));
    330 
    331                         }
    332                     }
    333                 }
    334             }
    335         }
    336     }
    337 
     295        }
     296    }
    338297
    339298    // Free the Chebyshev polynomials that were created in this routine.
     
    385344
    386345    // We scale the pixel positions to values between -1.0 and 1.0
    387     cScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
    388     rScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
     346    rScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
     347    cScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
    389348
    390349    // Determine how many Chebyshev polynomials are needed, then create them.
     
    427386    return(0);
    428387}
     388
     389/*****************************************************************************
     390p_psImagePixelInterpolation(image, x, y): this routine takes as input an
     391image and coordinates (x, y) and produces as output the corresponding pixel
     392value at the those coordinates.  For fractional corrdinates (x, y), 2-D
     393linear interpolation is performed on the image.
     394 *****************************************************************************/
     395float psImagePixelInterpolation(psImage *input,
     396                                float x,
     397                                float y)
     398{
     399    float floorX = 0.0;
     400    float floorY = 0.0;
     401    float fracX = 0.0;
     402    float fracY = 0.0;
     403    int intFloorX = 0;
     404    int intFloorY = 0;
     405    float x1 = 0.0;
     406    float x2 = 0.0;
     407    float pixel = 0.0;
     408
     409    if ((x < 0.0) ||
     410            (x > ((float) input->numRows-1)) ||
     411            (y < 0.0) ||
     412            (y > ((float) input->numCols-1))) {
     413        psAbort(__func__,
     414                "Fractional coordinates (%f %f) outside image range.", x, y);
     415    }
     416
     417    floorX = floorf(x);
     418    intFloorX = (int) floorX;
     419    fracX = x - floorX;
     420
     421    floorY = floorf(y);
     422    intFloorY = (int) floorY;
     423    fracY = y - floorY;
     424
     425    if (intFloorX == (input->numRows-1)) {
     426        pixel = input->data.F32[intFloorX][intFloorY];
     427        if (intFloorY < (input->numCols-1)) {
     428            pixel+= fracY * (input->data.F32[intFloorX][intFloorY+1] -
     429                             input->data.F32[intFloorX][intFloorY]);
     430        }
     431        return(pixel);
     432    } else if (intFloorX == (input->numCols-1)) {
     433        if (intFloorX < (input->numRows-1)) {
     434            pixel+= fracX * (input->data.F32[intFloorX+1][intFloorY] -
     435                             input->data.F32[intFloorX][intFloorY]);
     436        }
     437        return(pixel);
     438    }
     439
     440
     441    x1 = input->data.F32[intFloorX][intFloorY];
     442    x1+= fracY * (input->data.F32[intFloorX][intFloorY+1] -
     443                  input->data.F32[intFloorX][intFloorY]);
     444
     445    x2 = input->data.F32[intFloorX+1][intFloorY];
     446    x2+= fracY * (input->data.F32[intFloorX+1][intFloorY+1] -
     447                  input->data.F32[intFloorX+1][intFloorY]);
     448    pixel = x1;
     449    pixel+= fracX * (x2 - x1);
     450
     451    return(pixel);
     452}
Note: See TracChangeset for help on using the changeset viewer.