IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 16, 2004, 11:58:25 AM (22 years ago)
Author:
gusciora
Message:

The Chebyshev stuff is under construction.

File:
1 edited

Legend:

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

    r2634 r2735  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-12-04 19:22:25 $
     11 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-12-16 21:58:25 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    174174    return (chebPolys);
    175175}
    176 
    177 /*****************************************************************************
    178 psImageFitPolynomial(): This routine takes as input a 2-D image and produces
    179 as output the coefficients of the Chebyshev polynomials which match that
    180 input image.
    181   Input:
    182   Output:
    183   Internal Data Structures:
    184     chebPolys[i][j]
    185     sums[i][j]: This will contain the sum of
    186                 input->data.F32[x][y] *
    187                 psPolynomial1DEval(
    188 chebPolys[i],
    189 (float) x) *
    190                 psPolynomial1DEval(
    191 chebPolys[j],
    192 (float) y,
    193 );
    194         over all pixels (x,y) in the image.
    195   *****************************************************************************/
    196 psPolynomial2D* psImageFitPolynomialORIG(psPolynomial2D* coeffs,
    197         const psImage* input)
    198 {
    199     PS_IMAGE_CHECK_NULL(input, NULL);
    200     PS_IMAGE_CHECK_EMPTY(input, NULL);
    201     if ((input->type.type != PS_TYPE_S8) &&
    202             (input->type.type != PS_TYPE_U16) &&
    203             (input->type.type != PS_TYPE_F32) &&
    204             (input->type.type != PS_TYPE_F64)) {
    205         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unallowable image type.\n");
    206     }
    207     PS_POLY_CHECK_NULL(coeffs, NULL);
    208     PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);
    209     psS32 x = 0;
    210     psS32 y = 0;
    211     psS32 i = 0;
    212     psS32 j = 0;
    213     double **sums = NULL;
    214     psPolynomial1D* *chebPolys = NULL;
    215     psS32 maxChebyPoly = 0;
    216     double *cScalingFactors = NULL;
    217     double *rScalingFactors = NULL;
    218 
    219     // Create the sums[][] data structure.  This
    220     // will hold the LHS of
    221     // equation
    222     // 29 in the ADD: sums[k][l] = SUM {
    223     // image(x,y) * Tk(x) * Tl(y) }
    224     sums = (double **)psAlloc(coeffs->nX * sizeof(double *));
    225     for (i = 0; i < coeffs->nX; i++) {
    226         sums[i] = (double *)psAlloc(coeffs->nY * sizeof(double));
    227     }
    228     // We scale the pixel positions to values
    229     // between -1.0 and 1.0
    230     rScalingFactors = calcScaleFactors(input->numRows);
    231     cScalingFactors = calcScaleFactors(input->numCols);
    232 
    233     // Determine how many Chebyshev polynomials
    234     // are needed, then create them.
    235     maxChebyPoly = coeffs->nX;
    236     if (coeffs->nY > coeffs->nX) {
    237         maxChebyPoly = coeffs->nY;
    238     }
    239     chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);
    240 
    241     // Compute the sums[][] data structure.
    242     for (i = 0; i < coeffs->nX; i++) {
    243         for (j = 0; j < coeffs->nY; j++) {
    244             sums[i][j] = 0.0;
    245             for (x = 0; x < input->numRows; x++) {
    246                 for (y = 0; y < input->numCols; y++) {
    247                     double pixel;
    248                     if (input->type.type == PS_TYPE_S8) {
    249                         pixel = (double) input->data.S8[x][y];
    250                     } else if (input->type.type == PS_TYPE_U16) {
    251                         pixel = (double) input->data.U16[x][y];
    252                     } else if (input->type.type == PS_TYPE_F32) {
    253                         pixel = (double) input->data.F32[x][y];
    254                     } else if (input->type.type == PS_TYPE_F64) {
    255                         pixel = input->data.F64[x][y];
    256                     }
    257                     sums[i][j] += pixel * psPolynomial1DEval(chebPolys[i],rScalingFactors[x]) *
    258                                   psPolynomial1DEval(chebPolys[j], cScalingFactors[y]);
    259                 }
    260             }
    261         }
    262     }
    263 
    264     for (i = 0; i < coeffs->nX; i++) {
    265         for (j = 0; j < coeffs->nY; j++) {
    266             coeffs->coeff[i][j] = sums[i][j];
    267             coeffs->coeff[i][j] /= (double)(input->numRows * input->numCols);
    268 
    269             if ((i != 0) && (j != 0)) {
    270                 coeffs->coeff[i][j] *= 4.0;
    271             } else if ((i == 0) && (j == 0)) {
    272                 coeffs->coeff[i][j] *= 1.0;
    273             } else {
    274                 coeffs->coeff[i][j] *= 2.0;
    275             }
    276         }
    277     }
    278 
    279     // Free the Chebyshev polynomials that were
    280     // created in this routine.
    281     for (i = 0; i < maxChebyPoly; i++) {
    282         psFree(chebPolys[i]);
    283     }
    284     psFree(chebPolys);
    285 
    286     // Free some data
    287     for (i = 0; i < coeffs->nX; i++) {
    288         psFree(sums[i]);
    289     }
    290     psFree(sums);
    291     psFree(cScalingFactors);
    292     psFree(rScalingFactors);
    293 
    294     return (coeffs);
    295 }
    296 
    297 
    298 
    299176
    300177/*****************************************************************************
     
    339216    double *cScalingFactors = NULL;
    340217    double *rScalingFactors = NULL;
     218
     219    // Create the sums[][] data structure.  This
     220    // will hold the LHS of
     221    // equation
     222    // 29 in the ADD: sums[k][l] = SUM {
     223    // image(x,y) * Tk(x) * Tl(y) }
     224    sums = (double **)psAlloc(coeffs->nX * sizeof(double *));
     225    for (i = 0; i < coeffs->nX; i++) {
     226        sums[i] = (double *)psAlloc(coeffs->nY * sizeof(double));
     227    }
     228    // We scale the pixel positions to values
     229    // between -1.0 and 1.0
     230    rScalingFactors = calcScaleFactors(input->numRows);
     231    cScalingFactors = calcScaleFactors(input->numCols);
     232
     233    // Determine how many Chebyshev polynomials
     234    // are needed, then create them.
     235    maxChebyPoly = coeffs->nX;
     236    if (coeffs->nY > coeffs->nX) {
     237        maxChebyPoly = coeffs->nY;
     238    }
     239    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);
     240
     241    // Compute the sums[][] data structure.
     242    for (i = 0; i < coeffs->nX; i++) {
     243        for (j = 0; j < coeffs->nY; j++) {
     244            sums[i][j] = 0.0;
     245            for (x = 0; x < input->numRows; x++) {
     246                for (y = 0; y < input->numCols; y++) {
     247                    double pixel;
     248                    if (input->type.type == PS_TYPE_S8) {
     249                        pixel = (double) input->data.S8[x][y];
     250                    } else if (input->type.type == PS_TYPE_U16) {
     251                        pixel = (double) input->data.U16[x][y];
     252                    } else if (input->type.type == PS_TYPE_F32) {
     253                        pixel = (double) input->data.F32[x][y];
     254                    } else if (input->type.type == PS_TYPE_F64) {
     255                        pixel = input->data.F64[x][y];
     256                    }
     257                    sums[i][j] += pixel * psPolynomial1DEval(chebPolys[i],rScalingFactors[x]) *
     258                                  psPolynomial1DEval(chebPolys[j], cScalingFactors[y]);
     259                }
     260            }
     261        }
     262    }
     263
     264    for (i = 0; i < coeffs->nX; i++) {
     265        for (j = 0; j < coeffs->nY; j++) {
     266            coeffs->coeff[i][j] = sums[i][j];
     267            coeffs->coeff[i][j] /= (double)(input->numRows * input->numCols);
     268
     269            if ((i != 0) && (j != 0)) {
     270                coeffs->coeff[i][j] *= 4.0;
     271            } else if ((i == 0) && (j == 0)) {
     272                coeffs->coeff[i][j] *= 1.0;
     273            } else {
     274                coeffs->coeff[i][j] *= 2.0;
     275            }
     276        }
     277    }
     278
     279    // Free the Chebyshev polynomials that were
     280    // created in this routine.
     281    for (i = 0; i < maxChebyPoly; i++) {
     282        psFree(chebPolys[i]);
     283    }
     284    psFree(chebPolys);
     285
     286    // Free some data
     287    for (i = 0; i < coeffs->nX; i++) {
     288        psFree(sums[i]);
     289    }
     290    psFree(sums);
     291    psFree(cScalingFactors);
     292    psFree(rScalingFactors);
     293
     294    return (coeffs);
     295}
     296
     297
     298
     299
     300/*****************************************************************************
     301psImageFitPolynomial(): This routine takes as input a 2-D image and produces
     302as output the coefficients of the Chebyshev polynomials which match that
     303input image.
     304  Input:
     305  Output:
     306  Internal Data Structures:
     307    chebPolys[i][j]
     308    sums[i][j]: This will contain the sum of
     309                input->data.F32[x][y] *
     310                psPolynomial1DEval(
     311chebPolys[i],
     312(float) x) *
     313                psPolynomial1DEval(
     314chebPolys[j],
     315(float) y,
     316);
     317        over all pixels (x,y) in the image.
     318  *****************************************************************************/
     319psPolynomial2D* psImageFitPolynomialHMMM(psPolynomial2D* coeffs,
     320        const psImage* input)
     321{
     322    PS_IMAGE_CHECK_NULL(input, NULL);
     323    PS_IMAGE_CHECK_EMPTY(input, NULL);
     324    if ((input->type.type != PS_TYPE_S8) &&
     325            (input->type.type != PS_TYPE_U16) &&
     326            (input->type.type != PS_TYPE_F32) &&
     327            (input->type.type != PS_TYPE_F64)) {
     328        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unallowable image type.\n");
     329    }
     330    PS_POLY_CHECK_NULL(coeffs, NULL);
     331    PS_POLY_CHECK_TYPE(coeffs, PS_POLYNOMIAL_CHEB, NULL);
     332    psS32 x = 0;
     333    psS32 y = 0;
     334    psS32 i = 0;
     335    psS32 j = 0;
     336    double **sums = NULL;
     337    psPolynomial1D* *chebPolys = NULL;
     338    psS32 maxChebyPoly = 0;
     339    double *cScalingFactors = NULL;
     340    double *rScalingFactors = NULL;
    341341    psImage *nodes = psImageAlloc(input->numCols, input->numRows, PS_TYPE_F64);
    342342
Note: See TracChangeset for help on using the changeset viewer.