IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2262


Ignore:
Timestamp:
Nov 1, 2004, 4:03:56 PM (22 years ago)
Author:
gusciora
Message:

Added F64 types for the image fit routines, and test code.

Location:
trunk/psLib
Files:
3 edited

Legend:

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

    r2261 r2262  
    99*  @author GLG, MHPCC
    1010*
    11 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2004-11-02 01:52:43 $
     11*  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-11-02 02:03:56 $
    1313*
    1414*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    248248                psPolynomial1DEval((float) y, chebPolys[j]);
    249249        over all pixels (x,y) in the image.
    250  
    251 XXX: Currently we only support F32.
    252  *****************************************************************************/
     250  *****************************************************************************/
    253251psPolynomial2D* psImageFitPolynomial(psPolynomial2D* coeffs,
    254252                                     const psImage* input)
    255253{
     254    PS_IMAGE_CHECK_NULL(input, NULL);
     255    PS_IMAGE_CHECK_EMPTY(input, NULL);
     256    if ((input->type.type != PS_TYPE_S8) &&
     257            (input->type.type != PS_TYPE_U16) &&
     258            (input->type.type != PS_TYPE_F32) &&
     259            (input->type.type != PS_TYPE_F64)) {
     260        psError(__func__, "Unalowwable image type.\n");
     261    }
     262    PS_POLY_CHECK_NULL(coeffs, NULL);
     263    PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);
    256264    psS32 x = 0;
    257265    psS32 y = 0;
     
    308316            for (x = 0; x < input->numRows; x++) {
    309317                for (y = 0; y < input->numCols; y++) {
    310                     sums[i][j] +=
    311                         input->data.F32[x][y] *
    312                         psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
    313                         psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
     318                    double pixel;
     319                    if (input->type.type == PS_TYPE_S8) {
     320                        pixel = (double) input->data.S8[x][y];
     321                    } else if (input->type.type == PS_TYPE_U16) {
     322                        pixel = (double) input->data.U16[x][y];
     323                    } else if (input->type.type == PS_TYPE_F32) {
     324                        pixel = (double) input->data.F32[x][y];
     325                    } else if (input->type.type == PS_TYPE_F64) {
     326                        pixel = input->data.F64[x][y];
     327                    }
     328                    sums[i][j] += pixel *
     329                                  psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
     330                                  psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
    314331                }
    315332            }
     
    320337        for (j = 0; j < coeffs->nY; j++) {
    321338            coeffs->coeff[i][j] = sums[i][j];
    322             coeffs->coeff[i][j] /= (float)(input->numRows * input->numCols);
     339            coeffs->coeff[i][j] /= (double)(input->numRows * input->numCols);
    323340
    324341            if ((i != 0) && (j != 0)) {
     
    352369/*****************************************************************************
    353370XXX: Use static variables for chebyshev polynomials and scaling factors.
    354  
    355 XXX: Currently we only support F32.
    356      S8, U16, F32, F64
    357371 *****************************************************************************/
    358372psImage* psImageEvalPolynomial(psImage* input, const psPolynomial2D* coeffs)
     
    373387    psS32 i = 0;
    374388    psS32 j = 0;
    375     //    float **sums = NULL;
    376389    psPolynomial1D* *chebPolys = NULL;
    377390    psS32 maxChebyPoly = 0;
     
    407420                }
    408421            }
    409             input->data.F32[x][y] = polySum;
     422
     423            if (input->type.type == PS_TYPE_S8) {
     424                input->data.S8[x][y] = (char) polySum;
     425            } else if (input->type.type == PS_TYPE_U16) {
     426                input->data.U16[x][y] = (short int) polySum;
     427            } else if (input->type.type == PS_TYPE_F32) {
     428                input->data.F32[x][y] = (float) polySum;
     429            } else if (input->type.type == PS_TYPE_F64) {
     430                input->data.F64[x][y] = polySum;
     431            }
    410432        }
    411433    }
  • trunk/psLib/src/imageops/psImageStats.c

    r2261 r2262  
    99*  @author GLG, MHPCC
    1010*
    11 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2004-11-02 01:52:43 $
     11*  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-11-02 02:03:56 $
    1313*
    1414*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    248248                psPolynomial1DEval((float) y, chebPolys[j]);
    249249        over all pixels (x,y) in the image.
    250  
    251 XXX: Currently we only support F32.
    252  *****************************************************************************/
     250  *****************************************************************************/
    253251psPolynomial2D* psImageFitPolynomial(psPolynomial2D* coeffs,
    254252                                     const psImage* input)
    255253{
     254    PS_IMAGE_CHECK_NULL(input, NULL);
     255    PS_IMAGE_CHECK_EMPTY(input, NULL);
     256    if ((input->type.type != PS_TYPE_S8) &&
     257            (input->type.type != PS_TYPE_U16) &&
     258            (input->type.type != PS_TYPE_F32) &&
     259            (input->type.type != PS_TYPE_F64)) {
     260        psError(__func__, "Unalowwable image type.\n");
     261    }
     262    PS_POLY_CHECK_NULL(coeffs, NULL);
     263    PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);
    256264    psS32 x = 0;
    257265    psS32 y = 0;
     
    308316            for (x = 0; x < input->numRows; x++) {
    309317                for (y = 0; y < input->numCols; y++) {
    310                     sums[i][j] +=
    311                         input->data.F32[x][y] *
    312                         psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
    313                         psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
     318                    double pixel;
     319                    if (input->type.type == PS_TYPE_S8) {
     320                        pixel = (double) input->data.S8[x][y];
     321                    } else if (input->type.type == PS_TYPE_U16) {
     322                        pixel = (double) input->data.U16[x][y];
     323                    } else if (input->type.type == PS_TYPE_F32) {
     324                        pixel = (double) input->data.F32[x][y];
     325                    } else if (input->type.type == PS_TYPE_F64) {
     326                        pixel = input->data.F64[x][y];
     327                    }
     328                    sums[i][j] += pixel *
     329                                  psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
     330                                  psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
    314331                }
    315332            }
     
    320337        for (j = 0; j < coeffs->nY; j++) {
    321338            coeffs->coeff[i][j] = sums[i][j];
    322             coeffs->coeff[i][j] /= (float)(input->numRows * input->numCols);
     339            coeffs->coeff[i][j] /= (double)(input->numRows * input->numCols);
    323340
    324341            if ((i != 0) && (j != 0)) {
     
    352369/*****************************************************************************
    353370XXX: Use static variables for chebyshev polynomials and scaling factors.
    354  
    355 XXX: Currently we only support F32.
    356      S8, U16, F32, F64
    357371 *****************************************************************************/
    358372psImage* psImageEvalPolynomial(psImage* input, const psPolynomial2D* coeffs)
     
    373387    psS32 i = 0;
    374388    psS32 j = 0;
    375     //    float **sums = NULL;
    376389    psPolynomial1D* *chebPolys = NULL;
    377390    psS32 maxChebyPoly = 0;
     
    407420                }
    408421            }
    409             input->data.F32[x][y] = polySum;
     422
     423            if (input->type.type == PS_TYPE_S8) {
     424                input->data.S8[x][y] = (char) polySum;
     425            } else if (input->type.type == PS_TYPE_U16) {
     426                input->data.U16[x][y] = (short int) polySum;
     427            } else if (input->type.type == PS_TYPE_F32) {
     428                input->data.F32[x][y] = (float) polySum;
     429            } else if (input->type.type == PS_TYPE_F64) {
     430                input->data.F64[x][y] = polySum;
     431            }
    410432        }
    411433    }
  • trunk/psLib/test/image/tst_psImageStats04.c

    r2254 r2262  
    1515#include <float.h>
    1616#include <math.h>
    17 #define IMAGE_SIZE 8
     17#define IMAGE_SIZE 5
    1818#define NUM_COLS IMAGE_SIZE
    1919#define NUM_ROWS IMAGE_SIZE
     
    2929((A) + (B * X) + (C * Y) + (D * X * Y) + (E * X * X) + (F * Y * Y)) \
    3030
    31 psS32 FitCheby(int numCols, int numRows)
     31psS32 FitChebyF32(int numCols, int numRows)
    3232{
    3333    psImage *tmpImage     = NULL;
     
    100100}
    101101
     102psS32 FitChebyF64(int numCols, int numRows)
     103{
     104    psImage *tmpImage     = NULL;
     105    psImage *outImage     = NULL;
     106    psS32 testStatus      = true;
     107    psS32 memLeaks        = 0;
     108    psS32 i               = 0;
     109    psS32 j               = 0;
     110    psS32 currentId       = psMemGetId();
     111    double chi2 = 0.0;
     112
     113
     114    printf("psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
     115
     116    /*************************************************************************/
     117    /*  Allocate and initialize data structures                      */
     118    /*************************************************************************/
     119
     120    printPositiveTestHeader(stdout,
     121                            "psImageStats functions",
     122                            "psImageFitPolynomial(), psImageEvalPolynom()");
     123
     124    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
     125    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
     126    for (i=0;i<numRows;i++) {
     127        for (j=0;j<numCols;j++) {
     128            tmpImage->data.F64[i][j] = I_POLY(((double) i), ((double) j));
     129        }
     130    }
     131
     132    psPolynomial2D *chebys = psPolynomial2DAlloc(5, 5, PS_POLYNOMIAL_CHEB);
     133
     134    chebys = psImageFitPolynomial(chebys, tmpImage);
     135
     136    outImage = psImageEvalPolynomial(outImage, chebys);
     137
     138    chi2 = 0.0;
     139    for (i=0;i<numRows;i++) {
     140        for (j=0;j<numCols;j++) {
     141            double expect = tmpImage->data.F64[i][j];
     142            double actual = outImage->data.F64[i][j];
     143            chi2+= (actual-expect) * (actual-expect);
     144            if (fabs((actual - expect) / expect) > ERROR_TOL) {
     145                printf("pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
     146            }
     147        }
     148    }
     149    chi2/= ((double) (numCols * numRows));
     150    printf("The chi-squared per pixel is %f\n", chi2);
     151
     152    psFree(tmpImage);
     153    psFree(outImage);
     154    psFree(chebys);
     155    psMemCheckCorruption(1);
     156    printFooter(stdout,
     157                "psImageStats functions",
     158                "psImagePixelInterpolation()",
     159                testStatus);
     160
     161    /*************************************************************************/
     162    /*  Deallocate data structures                                   */
     163    /*************************************************************************/
     164    psMemCheckCorruption(1);
     165    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     166    if (0 != memLeaks) {
     167        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     168    }
     169
     170    return(!testStatus);
     171}
     172
    102173int main()
    103174{
    104     FitCheby(1, 1);
    105     FitCheby(1, NUM_ROWS);
    106     FitCheby(1, 1);
    107     FitCheby(NUM_COLS, 1);
    108     FitCheby(NUM_COLS, NUM_ROWS);
     175    FitChebyF32(1, 1);
     176    FitChebyF32(1, NUM_ROWS);
     177    FitChebyF32(1, 1);
     178    FitChebyF32(NUM_COLS, 1);
     179    FitChebyF32(NUM_COLS, NUM_ROWS);
     180    FitChebyF64(1, 1);
     181    FitChebyF64(1, NUM_ROWS);
     182    FitChebyF64(1, 1);
     183    FitChebyF64(NUM_COLS, 1);
     184    FitChebyF64(NUM_COLS, NUM_ROWS);
    109185}
Note: See TracChangeset for help on using the changeset viewer.