IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2261


Ignore:
Timestamp:
Nov 1, 2004, 3:52:43 PM (22 years ago)
Author:
gusciora
Message:

Changing the image fit routines to be of "double" type.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psConstants.h

    r2230 r2261  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-28 23:03:11 $
     8 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-11-02 01:52:43 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    225225} \
    226226
    227 
     227#define PS_POLY_CHECK_TYPE(NAME, TYPE, RVAL) \
     228if (NAME->type != TYPE) { \
     229    psError(__func__,"Unallowable operation: polynomial %s has wrong type.", #NAME); \
     230    return(RVAL); \
     231} \
    228232
    229233/*****************************************************************************
  • trunk/psLib/src/image/psImageStats.c

    r2212 r2261  
    99*  @author GLG, MHPCC
    1010*
    11 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2004-10-27 20:07:17 $
     11*  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-11-02 01:52:43 $
    1313*
    1414*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    149149}
    150150
     151double *CalcScaleFactors(psS32 n)
     152{
     153    psS32 i = 0;
     154    double tmp = 0.0;
     155    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
     156
     157    for (i = 0; i < n; i++) {
     158        tmp = (double)(n - i);
     159        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
     160        scalingFactors[i] = cos(tmp);
     161    }
     162
     163    return (scalingFactors);
     164}
     165
    151166// XXX: Why do we have this function?
    152 float *p_psCalcScaleFactorsFit(psS32 n)
    153 {
    154     psS32 i = 0;
    155     float tmp = 0.0;
    156     float *scalingFactors = (float *)psAlloc(n * sizeof(float));
     167double *CalcScaleFactorsFit(psS32 n)
     168{
     169    psS32 i = 0;
     170    double tmp = 0.0;
     171    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
    157172
    158173    for (i = 0; i < n; i++) {
    159         // ((2.0 * (float) i) / ((float) (n-1)))
    160         // - 1.0;
    161         // tmp = (float) (i + 1);
    162         tmp = (float)(n - i);
    163         tmp = (M_PI * (tmp - 0.5)) / ((float)n);
     174        tmp = (double)(n - i);
     175        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
    164176        scalingFactors[i] = cos(tmp);
    165177    }
     
    169181
    170182/*****************************************************************************
    171 p_psCalcScaleFactorsEval(n): The Chebyshev polynomials are defined over the
     183CalcScaleFactorsEval(n): The Chebyshev polynomials are defined over the
    172184interval [-1.0 : 1.0].  Images typically have sizes of 512x512 or more.  In
    173185order to use Chebyshev polynomials, we must scale the coordinates from
     
    175187output a vector of evenly spaced floating point values between -1.0:1.0.
    176188 *****************************************************************************/
    177 float *p_psCalcScaleFactorsEval(psS32 n)
    178 {
    179     psS32 i = 0;
    180     float tmp = 0.0;
    181 
    182     return p_psCalcScaleFactorsFit(n);
    183 
    184     printf("Should not get here\n");
    185     float *scalingFactors = (float *)psAlloc(n * sizeof(float));
     189double *CalcScaleFactorsEval(psS32 n)
     190{
     191    psS32 i = 0;
     192    double tmp = 0.0;
     193
     194    return(CalcScaleFactorsFit(n));
     195
     196    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
    186197
    187198    for (i = 0; i < n; i++) {
    188         // scalingFactors[i] = ((2.0 * (float) i)
    189         // / ((float) (n-1))) - 1.0;
    190         tmp = (float)(n - i);
    191         tmp = (M_PI * (tmp - 0.5)) / ((float)n);
     199        tmp = (double)(n - i);
     200        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
    192201        scalingFactors[i] = cos(tmp);
    193202    }
     
    249258    psS32 i = 0;
    250259    psS32 j = 0;
    251     float **sums = NULL;
     260    double **sums = NULL;
    252261    psPolynomial1D* *chebPolys = NULL;
    253262    psS32 maxChebyPoly = 0;
    254     float *cScalingFactors = NULL;
    255     float *rScalingFactors = NULL;
     263    double *cScalingFactors = NULL;
     264    double *rScalingFactors = NULL;
    256265
    257266    // Check for null inputs
     
    275284    // 29 in the ADD: sums[k][l] = SUM {
    276285    // image(x,y) * Tk(x) * Tl(y) }
    277     sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
     286    sums = (double **)psAlloc(coeffs->nX * sizeof(double *));
    278287    for (i = 0; i < coeffs->nX; i++) {
    279         sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
     288        sums[i] = (double *)psAlloc(coeffs->nY * sizeof(double));
    280289    }
    281290    // We scale the pixel positions to values
    282291    // between -1.0 and 1.0
    283     rScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
    284     cScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
     292    rScalingFactors = CalcScaleFactors(input->numRows);
     293    cScalingFactors = CalcScaleFactors(input->numCols);
    285294
    286295    // Determine how many Chebyshev polynomials
     
    292301    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);
    293302
    294 
    295     /*
    296         // Sanity check for the Chebyshevs.
    297         for (i = 0; i < coeffs->nX; i++) {
    298             for (j = 0; j < coeffs->nY; j++) {
    299                 tmp = 0.0;
    300                 for (x = 0; x < input->numRows; x++) {
    301                     tmp +=
    302                         psPolynomial1DEval
    303                         (rScalingFactors[x], chebPolys[i]) * psPolynomial1DEval(rScalingFactors[x], chebPolys[j]);
    304      
    305                 }
    306                 // printf("SUM(Cheby(%d) * Cheby(%d))
    307                 // is %f\n", i, j, tmp);
    308             }
    309         }
    310     */
    311303
    312304    // Compute the sums[][] data structure.
     
    362354 
    363355XXX: Currently we only support F32.
     356     S8, U16, F32, F64
    364357 *****************************************************************************/
    365358psImage* psImageEvalPolynomial(psImage* input, const psPolynomial2D* coeffs)
    366359{
     360    PS_IMAGE_CHECK_NULL(input, NULL);
     361    PS_IMAGE_CHECK_EMPTY(input, NULL);
     362    if ((input->type.type != PS_TYPE_S8) &&
     363            (input->type.type != PS_TYPE_U16) &&
     364            (input->type.type != PS_TYPE_F32) &&
     365            (input->type.type != PS_TYPE_F64)) {
     366        psError(__func__, "Unalowwable image type.\n");
     367    }
     368    PS_POLY_CHECK_NULL(coeffs, NULL);
     369    PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);
     370
    367371    psS32 x = 0;
    368372    psS32 y = 0;
     
    372376    psPolynomial1D* *chebPolys = NULL;
    373377    psS32 maxChebyPoly = 0;
    374     float *cScalingFactors = NULL;
    375     float *rScalingFactors = NULL;
    376     float polySum = 0.0;
    377 
    378     // Create the sums[][] data structure.  This will hold the LHS of
    379     // equation 29 in the ADD:
    380     //         sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
    381     //
    382     //    sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
    383     //    for (i = 0; i < coeffs->nX; i++) {
    384     //        sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
    385     //    }
    386     //    for (i = 0; i < coeffs->nX; i++) {
    387     //        for (j = 0; j < coeffs->nY; j++) {
    388     //            sums[i][j] = 0.0;
    389     //        }
    390     //    }
    391 
    392 
    393     // Check for null inputs
    394     if (input == NULL) {
    395         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageEvalPolynomial",
    396                    PS_ERR_BAD_PARAMETER_NULL, true,
    397                    PS_ERRORTEXT_psImage_IMAGE_NULL);
    398         return NULL;
    399     }
    400 
    401     if (coeffs == NULL) {
    402         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageEvalPolynomial",
    403                    PS_ERR_BAD_PARAMETER_NULL, true,
    404                    PS_ERRORTEXT_psImage_COEFF_NULL);
    405         return NULL;
    406     }
     378    double *cScalingFactors = NULL;
     379    double *rScalingFactors = NULL;
     380    double polySum = 0.0;
     381
    407382
    408383    // We scale the pixel positions to values between -1.0 and 1.0
    409384    // Use static data structures here.
    410     rScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
    411     cScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
     385    rScalingFactors = CalcScaleFactors(input->numRows);
     386    cScalingFactors = CalcScaleFactors(input->numCols);
    412387
    413388    // Determine how many Chebyshev polynomials
  • trunk/psLib/src/imageops/psImageStats.c

    r2212 r2261  
    99*  @author GLG, MHPCC
    1010*
    11 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2004-10-27 20:07:17 $
     11*  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2004-11-02 01:52:43 $
    1313*
    1414*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    149149}
    150150
     151double *CalcScaleFactors(psS32 n)
     152{
     153    psS32 i = 0;
     154    double tmp = 0.0;
     155    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
     156
     157    for (i = 0; i < n; i++) {
     158        tmp = (double)(n - i);
     159        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
     160        scalingFactors[i] = cos(tmp);
     161    }
     162
     163    return (scalingFactors);
     164}
     165
    151166// XXX: Why do we have this function?
    152 float *p_psCalcScaleFactorsFit(psS32 n)
    153 {
    154     psS32 i = 0;
    155     float tmp = 0.0;
    156     float *scalingFactors = (float *)psAlloc(n * sizeof(float));
     167double *CalcScaleFactorsFit(psS32 n)
     168{
     169    psS32 i = 0;
     170    double tmp = 0.0;
     171    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
    157172
    158173    for (i = 0; i < n; i++) {
    159         // ((2.0 * (float) i) / ((float) (n-1)))
    160         // - 1.0;
    161         // tmp = (float) (i + 1);
    162         tmp = (float)(n - i);
    163         tmp = (M_PI * (tmp - 0.5)) / ((float)n);
     174        tmp = (double)(n - i);
     175        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
    164176        scalingFactors[i] = cos(tmp);
    165177    }
     
    169181
    170182/*****************************************************************************
    171 p_psCalcScaleFactorsEval(n): The Chebyshev polynomials are defined over the
     183CalcScaleFactorsEval(n): The Chebyshev polynomials are defined over the
    172184interval [-1.0 : 1.0].  Images typically have sizes of 512x512 or more.  In
    173185order to use Chebyshev polynomials, we must scale the coordinates from
     
    175187output a vector of evenly spaced floating point values between -1.0:1.0.
    176188 *****************************************************************************/
    177 float *p_psCalcScaleFactorsEval(psS32 n)
    178 {
    179     psS32 i = 0;
    180     float tmp = 0.0;
    181 
    182     return p_psCalcScaleFactorsFit(n);
    183 
    184     printf("Should not get here\n");
    185     float *scalingFactors = (float *)psAlloc(n * sizeof(float));
     189double *CalcScaleFactorsEval(psS32 n)
     190{
     191    psS32 i = 0;
     192    double tmp = 0.0;
     193
     194    return(CalcScaleFactorsFit(n));
     195
     196    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
    186197
    187198    for (i = 0; i < n; i++) {
    188         // scalingFactors[i] = ((2.0 * (float) i)
    189         // / ((float) (n-1))) - 1.0;
    190         tmp = (float)(n - i);
    191         tmp = (M_PI * (tmp - 0.5)) / ((float)n);
     199        tmp = (double)(n - i);
     200        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
    192201        scalingFactors[i] = cos(tmp);
    193202    }
     
    249258    psS32 i = 0;
    250259    psS32 j = 0;
    251     float **sums = NULL;
     260    double **sums = NULL;
    252261    psPolynomial1D* *chebPolys = NULL;
    253262    psS32 maxChebyPoly = 0;
    254     float *cScalingFactors = NULL;
    255     float *rScalingFactors = NULL;
     263    double *cScalingFactors = NULL;
     264    double *rScalingFactors = NULL;
    256265
    257266    // Check for null inputs
     
    275284    // 29 in the ADD: sums[k][l] = SUM {
    276285    // image(x,y) * Tk(x) * Tl(y) }
    277     sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
     286    sums = (double **)psAlloc(coeffs->nX * sizeof(double *));
    278287    for (i = 0; i < coeffs->nX; i++) {
    279         sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
     288        sums[i] = (double *)psAlloc(coeffs->nY * sizeof(double));
    280289    }
    281290    // We scale the pixel positions to values
    282291    // between -1.0 and 1.0
    283     rScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
    284     cScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
     292    rScalingFactors = CalcScaleFactors(input->numRows);
     293    cScalingFactors = CalcScaleFactors(input->numCols);
    285294
    286295    // Determine how many Chebyshev polynomials
     
    292301    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);
    293302
    294 
    295     /*
    296         // Sanity check for the Chebyshevs.
    297         for (i = 0; i < coeffs->nX; i++) {
    298             for (j = 0; j < coeffs->nY; j++) {
    299                 tmp = 0.0;
    300                 for (x = 0; x < input->numRows; x++) {
    301                     tmp +=
    302                         psPolynomial1DEval
    303                         (rScalingFactors[x], chebPolys[i]) * psPolynomial1DEval(rScalingFactors[x], chebPolys[j]);
    304      
    305                 }
    306                 // printf("SUM(Cheby(%d) * Cheby(%d))
    307                 // is %f\n", i, j, tmp);
    308             }
    309         }
    310     */
    311303
    312304    // Compute the sums[][] data structure.
     
    362354 
    363355XXX: Currently we only support F32.
     356     S8, U16, F32, F64
    364357 *****************************************************************************/
    365358psImage* psImageEvalPolynomial(psImage* input, const psPolynomial2D* coeffs)
    366359{
     360    PS_IMAGE_CHECK_NULL(input, NULL);
     361    PS_IMAGE_CHECK_EMPTY(input, NULL);
     362    if ((input->type.type != PS_TYPE_S8) &&
     363            (input->type.type != PS_TYPE_U16) &&
     364            (input->type.type != PS_TYPE_F32) &&
     365            (input->type.type != PS_TYPE_F64)) {
     366        psError(__func__, "Unalowwable image type.\n");
     367    }
     368    PS_POLY_CHECK_NULL(coeffs, NULL);
     369    PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);
     370
    367371    psS32 x = 0;
    368372    psS32 y = 0;
     
    372376    psPolynomial1D* *chebPolys = NULL;
    373377    psS32 maxChebyPoly = 0;
    374     float *cScalingFactors = NULL;
    375     float *rScalingFactors = NULL;
    376     float polySum = 0.0;
    377 
    378     // Create the sums[][] data structure.  This will hold the LHS of
    379     // equation 29 in the ADD:
    380     //         sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
    381     //
    382     //    sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
    383     //    for (i = 0; i < coeffs->nX; i++) {
    384     //        sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
    385     //    }
    386     //    for (i = 0; i < coeffs->nX; i++) {
    387     //        for (j = 0; j < coeffs->nY; j++) {
    388     //            sums[i][j] = 0.0;
    389     //        }
    390     //    }
    391 
    392 
    393     // Check for null inputs
    394     if (input == NULL) {
    395         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageEvalPolynomial",
    396                    PS_ERR_BAD_PARAMETER_NULL, true,
    397                    PS_ERRORTEXT_psImage_IMAGE_NULL);
    398         return NULL;
    399     }
    400 
    401     if (coeffs == NULL) {
    402         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageEvalPolynomial",
    403                    PS_ERR_BAD_PARAMETER_NULL, true,
    404                    PS_ERRORTEXT_psImage_COEFF_NULL);
    405         return NULL;
    406     }
     378    double *cScalingFactors = NULL;
     379    double *rScalingFactors = NULL;
     380    double polySum = 0.0;
     381
    407382
    408383    // We scale the pixel positions to values between -1.0 and 1.0
    409384    // Use static data structures here.
    410     rScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
    411     cScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
     385    rScalingFactors = CalcScaleFactors(input->numRows);
     386    cScalingFactors = CalcScaleFactors(input->numCols);
    412387
    413388    // Determine how many Chebyshev polynomials
  • trunk/psLib/src/math/psConstants.h

    r2230 r2261  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-28 23:03:11 $
     8 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-11-02 01:52:43 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    225225} \
    226226
    227 
     227#define PS_POLY_CHECK_TYPE(NAME, TYPE, RVAL) \
     228if (NAME->type != TYPE) { \
     229    psError(__func__,"Unallowable operation: polynomial %s has wrong type.", #NAME); \
     230    return(RVAL); \
     231} \
    228232
    229233/*****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.