IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

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

    r1406 r1407  
     1
    12/** @file psImageStats.c
    23*  \brief Routines for calculating statistics on images.
     
    910*  @author George Gusciora, MHPCC
    1011*
    11 *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2004-08-06 22:34:05 $
     12*  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-08-07 00:06:06 $
    1314*
    1415*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3233
    3334/// This routine must determine the various statistics for the image.
     35
    3436/*****************************************************************************
    3537    NOTE: verify that image/mask have the correct types, and sizes.
    3638 *****************************************************************************/
    37 psStats *psImageStats(psStats *stats,
    38                       psImage *in,
    39                       psImage *mask,
    40                       int maskVal)
    41 {
    42     psVector* junkData=NULL;
    43     psVector* junkMask=NULL;
     39psStats *psImageStats(psStats * stats, psImage * in, psImage * mask, int maskVal)
     40{
     41    psVector *junkData = NULL;
     42    psVector *junkMask = NULL;
    4443
    4544    if (stats == NULL) {
    46         psError(__func__,"The input psStats struct can not be NULL.");
     45        psError(__func__, "The input psStats struct can not be NULL.");
    4746        return NULL;
    4847    }
    4948
    5049    if (in == NULL) {
    51         psError(__func__,"The input image can not be NULL.");
     50        psError(__func__, "The input image can not be NULL.");
    5251        return NULL;
    5352    }
    5453
    5554    if (stats->options == 0) {
    56         psError(__func__,"No statistic option/operation was specified.");
     55        psError(__func__, "No statistic option/operation was specified.");
    5756        return stats;
    5857    }
    59 
    60     // stuff the image data into a psVector struct.
     58    // stuff the image data into a psVector
     59    // struct.
    6160    junkData = psAlloc(sizeof(psVector));
    6261    junkData->type = in->type;
    63     junkData->nalloc = in->numRows*in->numCols;
     62    junkData->nalloc = in->numRows * in->numCols;
    6463    junkData->n = junkData->nalloc;
    65     junkData->data.V = in->data.V[0];    // since psImage data is contiguous...
     64    junkData->data.V = in->data.V[0];      // since
     65    // psImage
     66    // data
     67    // is
     68    // contiguous...
    6669
    6770    if (mask != NULL) {
    6871        if (mask->type.type != PS_TYPE_MASK) {
    69             psError(__func__, "Expected the mask image type not found (type=%x)",
    70                     mask->type.type);
     72            psError(__func__, "Expected the mask image type not found (type=%x)", mask->type.type);
    7173            psFree(junkData);
    7274            return NULL;
    7375        }
    74 
    75         // stuff the mask data into a psVector struct.
     76        // stuff the mask data into a psVector
     77        // struct.
    7678        junkMask = psAlloc(sizeof(psVector));
    7779        junkMask->type = mask->type;
    78         junkMask->nalloc = mask->numRows*mask->numCols;
     80        junkMask->nalloc = mask->numRows * mask->numCols;
    7981        junkMask->n = junkMask->nalloc;
    8082        junkMask->data.V = mask->data.V[0];
     
    8587    psFree(junkMask);
    8688    psFree(junkData);
    87     return(stats);
     89    return (stats);
    8890}
    8991
     
    9395    NOTE: verify that image/mask have the, correct types and  sizes.
    9496 *****************************************************************************/
    95 psHistogram *psImageHistogram(psHistogram *out,
    96                               psImage *in,
    97                               psImage *mask,
    98                               unsigned int maskVal)
    99 {
    100     psVector *junkData=NULL;
    101     psVector *junkMask=NULL;
     97psHistogram *psImageHistogram(psHistogram * out, psImage * in, psImage * mask, unsigned int maskVal)
     98{
     99    psVector *junkData = NULL;
     100    psVector *junkMask = NULL;
    102101
    103102    // NOTE: Verify this action.
    104     if ((out == NULL) ||
    105             (in == NULL)) {
    106         return(NULL);
     103    if ((out == NULL) || (in == NULL)) {
     104        return (NULL);
    107105    }
    108106
    109107    junkData = psAlloc(sizeof(psVector));
    110108    junkData->type = in->type;
    111     junkData->nalloc = in->numRows*in->numCols;
     109    junkData->nalloc = in->numRows * in->numCols;
    112110    junkData->n = junkData->nalloc;
    113     junkData->data.V = in->data.V[0];    // since psImage data is contiguous...
     111    junkData->data.V = in->data.V[0];      // since
     112    // psImage
     113    // data
     114    // is
     115    // contiguous...
    114116
    115117    if (mask != NULL) {
    116118        if (mask->type.type != PS_TYPE_MASK) {
    117             psError(__func__, "Expected the mask image type not found (type=%x)",
    118                     mask->type.type);
     119            psError(__func__, "Expected the mask image type not found (type=%x)", mask->type.type);
    119120            psFree(junkData);
    120121            return NULL;
    121122        }
    122 
    123         // stuff the mask data into a psVector struct.
     123        // stuff the mask data into a psVector
     124        // struct.
    124125        junkMask = psAlloc(sizeof(psVector));
    125126        junkMask->type = mask->type;
    126         junkMask->nalloc = mask->numRows*mask->numCols;
     127        junkMask->nalloc = mask->numRows * mask->numCols;
    127128        junkMask->n = junkMask->nalloc;
    128129        junkMask->data.V = mask->data.V[0];
     
    134135    psFree(junkData);
    135136
    136     return(out);
     137    return (out);
    137138}
    138139
     
    141142    int i = 0;
    142143    float tmp = 0.0;
    143     float *scalingFactors = (float *) psAlloc(n * sizeof(float));
    144 
    145     for (i=0;i<n;i++) {
    146         //     ((2.0 * (float) i) / ((float) (n-1))) - 1.0;
    147         //        tmp = (float) (i + 1);
    148         tmp = (float) (n - i);
    149         tmp = (M_PI * (tmp - 0.5)) / ((float) n);
     144    float *scalingFactors = (float *)psAlloc(n * sizeof(float));
     145
     146    for (i = 0; i < n; i++) {
     147        // ((2.0 * (float) i) / ((float) (n-1)))
     148        // - 1.0;
     149        // tmp = (float) (i + 1);
     150        tmp = (float)(n - i);
     151        tmp = (M_PI * (tmp - 0.5)) / ((float)n);
    150152        scalingFactors[i] = cos(tmp);
    151153    }
    152154
    153     return(scalingFactors);
     155    return (scalingFactors);
    154156}
    155157
     
    165167    int i = 0;
    166168    float tmp = 0.0;
     169
    167170    return p_psCalcScaleFactorsFit(n);
    168171
    169172    printf("Should not get here\n");
    170     float *scalingFactors = (float *) psAlloc(n * sizeof(float));
    171     for (i=0;i<n;i++) {
    172         //          scalingFactors[i] = ((2.0 * (float) i) / ((float) (n-1))) - 1.0;
    173         tmp = (float) (n - i);
    174         tmp = (M_PI * (tmp - 0.5)) / ((float) n);
     173    float *scalingFactors = (float *)psAlloc(n * sizeof(float));
     174
     175    for (i = 0; i < n; i++) {
     176        // scalingFactors[i] = ((2.0 * (float) i)
     177        // / ((float) (n-1))) - 1.0;
     178        tmp = (float)(n - i);
     179        tmp = (M_PI * (tmp - 0.5)) / ((float)n);
    175180        scalingFactors[i] = cos(tmp);
    176181    }
    177     return(scalingFactors);
     182    return (scalingFactors);
    178183}
    179184
     
    184189    int j = 0;
    185190
    186     chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly *
    187                                             sizeof(psPolynomial1D *));
    188     for (i=0;i<maxChebyPoly;i++) {
    189         chebPolys[i] = psPolynomial1DAlloc(i+1);
    190     }
    191 
    192     // Create the Chebyshev polynomials.  Polynomial i has i-th order.
     191    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
     192    for (i = 0; i < maxChebyPoly; i++) {
     193        chebPolys[i] = psPolynomial1DAlloc(i + 1);
     194    }
     195
     196    // Create the Chebyshev polynomials.
     197    // Polynomial i has i-th order.
    193198    chebPolys[0]->coeff[0] = 1;
    194199    chebPolys[1]->coeff[1] = 1;
    195     for (i=2;i<maxChebyPoly;i++) {
    196         for (j=0;j<chebPolys[i-1]->n;j++) {
    197             chebPolys[i]->coeff[j+1] = 2 * chebPolys[i-1]->coeff[j];
    198         }
    199         for (j=0;j<chebPolys[i-2]->n;j++) {
    200             chebPolys[i]->coeff[j]-= chebPolys[i-2]->coeff[j];
    201         }
    202     }
    203 
    204     return(chebPolys);
    205 }
    206 
     200    for (i = 2; i < maxChebyPoly; i++) {
     201        for (j = 0; j < chebPolys[i - 1]->n; j++) {
     202            chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
     203        }
     204        for (j = 0; j < chebPolys[i - 2]->n; j++) {
     205            chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     206        }
     207    }
     208
     209    return (chebPolys);
     210}
    207211
    208212/*****************************************************************************
     
    220224        over all pixels (x,y) in the image.
    221225 *****************************************************************************/
    222 psPolynomial2D *
    223 psImageFitPolynomial(const psImage *input,
    224                      psPolynomial2D *coeffs)
     226psPolynomial2D *psImageFitPolynomial(const psImage * input, psPolynomial2D * coeffs)
    225227{
    226228    int x = 0;
     
    235237    float tmp = 0.0;
    236238
    237     // Create the sums[][] data structure.  This will hold the LHS of equation
    238     // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
    239     sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
    240     for (i=0;i<coeffs->nX;i++) {
    241         sums[i] = (float *) psAlloc(coeffs->nY * sizeof(float));
    242     }
    243 
    244     // We scale the pixel positions to values between -1.0 and 1.0
     239    // Create the sums[][] data structure.  This
     240    // will hold the LHS of
     241    // equation
     242    // 29 in the ADD: sums[k][l] = SUM {
     243    // image(x,y) * Tk(x) * Tl(y) }
     244    sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
     245    for (i = 0; i < coeffs->nX; i++) {
     246        sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
     247    }
     248
     249    // We scale the pixel positions to values
     250    // between -1.0 and 1.0
    245251    rScalingFactors = p_psCalcScaleFactorsFit(input->numRows);
    246252    cScalingFactors = p_psCalcScaleFactorsFit(input->numCols);
    247253
    248     // Determine how many Chebyshev polynomials are needed, then create them.
     254    // Determine how many Chebyshev polynomials
     255    // are needed, then create them.
    249256    maxChebyPoly = coeffs->nX;
    250257    if (coeffs->nY > coeffs->nX) {
     
    254261
    255262    // Sanity check for the Chebyshevs.
    256     for (i=0;i<coeffs->nX;i++) {
    257         for (j=0;j<coeffs->nY;j++) {
     263    for (i = 0; i < coeffs->nX; i++) {
     264        for (j = 0; j < coeffs->nY; j++) {
    258265            tmp = 0.0;
    259             for (x=0;x<input->numRows;x++) {
    260                 tmp+= psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
    261                       psPolynomial1DEval(rScalingFactors[x], chebPolys[j]);
     266            for (x = 0; x < input->numRows; x++) {
     267                tmp +=
     268                    psPolynomial1DEval
     269                    (rScalingFactors[x], chebPolys[i]) * psPolynomial1DEval(rScalingFactors[x], chebPolys[j]);
    262270
    263271            }
    264             //printf("SUM(Cheby(%d) * Cheby(%d)) is %f\n", i, j, tmp);
     272            // printf("SUM(Cheby(%d) * Cheby(%d))
     273            // is %f\n", i, j, tmp);
    265274        }
    266275    }
    267276
    268277    // Compute the sums[][] data structure.
    269     for (i=0;i<coeffs->nX;i++) {
    270         for (j=0;j<coeffs->nY;j++) {
     278    for (i = 0; i < coeffs->nX; i++) {
     279        for (j = 0; j < coeffs->nY; j++) {
    271280            sums[i][j] = 0.0;
    272             for (x=0;x<input->numRows;x++) {
    273                 for (y=0;y<input->numCols;y++) {
    274                     sums[i][j]+= input->data.F32[x][y] *
    275                                  psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
    276                                  psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
     281            for (x = 0; x < input->numRows; x++) {
     282                for (y = 0; y < input->numCols; y++) {
     283                    sums[i][j] +=
     284                        input->data.F32[x][y] *
     285                        psPolynomial1DEval
     286                        (rScalingFactors[x],
     287                         chebPolys[i]) * psPolynomial1DEval(cScalingFactors[y], chebPolys[j]);
    277288                }
    278289            }
     
    280291    }
    281292
    282     for (i=0;i<coeffs->nX;i++) {
    283         for (j=0;j<coeffs->nY;j++) {
     293    for (i = 0; i < coeffs->nX; i++) {
     294        for (j = 0; j < coeffs->nY; j++) {
    284295            coeffs->coeff[i][j] = sums[i][j];
    285             coeffs->coeff[i][j]/= (float) (input->numRows * input->numCols);
     296            coeffs->coeff[i][j] /= (float)(input->numRows * input->numCols);
    286297
    287298            if ((i != 0) && (j != 0)) {
    288                 coeffs->coeff[i][j]*= 4.0;
    289             } else
    290                 if ((i == 0) && (j == 0)) {
    291                     coeffs->coeff[i][j]*= 1.0;
    292                 } else {
    293                     coeffs->coeff[i][j]*= 2.0;
    294                 }
    295         }
    296     }
    297 
    298     // Free the Chebyshev polynomials that were created in this routine.
    299     for (i=0;i<maxChebyPoly;i++) {
     299                coeffs->coeff[i][j] *= 4.0;
     300            } else if ((i == 0) && (j == 0)) {
     301                coeffs->coeff[i][j] *= 1.0;
     302            } else {
     303                coeffs->coeff[i][j] *= 2.0;
     304            }
     305        }
     306    }
     307
     308    // Free the Chebyshev polynomials that were
     309    // created in this routine.
     310    for (i = 0; i < maxChebyPoly; i++) {
    300311        psFree(chebPolys[i]);
    301312    }
     
    303314
    304315    // Free some data
    305     for (i=0;i<coeffs->nX;i++) {
     316    for (i = 0; i < coeffs->nX; i++) {
    306317        psFree(sums[i]);
    307318    }
     
    310321    psFree(rScalingFactors);
    311322
    312     return(coeffs);
     323    return (coeffs);
    313324}
    314325
     
    316327 
    317328 *****************************************************************************/
    318 int
    319 psImageEvalPolynomial(const psImage *input,
    320                       const psPolynomial2D *coeffs)
     329int psImageEvalPolynomial(const psImage * input, const psPolynomial2D * coeffs)
    321330{
    322331    int x = 0;
     
    331340    float polySum = 0.0;
    332341
    333     // Create the sums[][] data structure.  This will hold the LHS of equation
    334     // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
    335     sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
    336     for (i=0;i<coeffs->nX;i++) {
    337         sums[i] = (float *) psAlloc(coeffs->nY * sizeof(float));
    338     }
    339     for (i=0;i<coeffs->nX;i++) {
    340         for (j=0;j<coeffs->nY;j++) {
     342    // Create the sums[][] data structure.  This
     343    // will hold the LHS of
     344    // equation
     345    // 29 in the ADD: sums[k][l] = SUM {
     346    // image(x,y) * Tk(x) * Tl(y) }
     347    sums = (float **)psAlloc(coeffs->nX * sizeof(float *));
     348    for (i = 0; i < coeffs->nX; i++) {
     349        sums[i] = (float *)psAlloc(coeffs->nY * sizeof(float));
     350    }
     351    for (i = 0; i < coeffs->nX; i++) {
     352        for (j = 0; j < coeffs->nY; j++) {
    341353            sums[i][j] = 0.0;
    342354        }
    343355    }
    344356
    345     // We scale the pixel positions to values between -1.0 and 1.0
     357    // We scale the pixel positions to values
     358    // between -1.0 and 1.0
    346359    rScalingFactors = p_psCalcScaleFactorsEval(input->numRows);
    347360    cScalingFactors = p_psCalcScaleFactorsEval(input->numCols);
    348361
    349     // Determine how many Chebyshev polynomials are needed, then create them.
     362    // Determine how many Chebyshev polynomials
     363    // are needed, then create them.
    350364    maxChebyPoly = coeffs->nX;
    351365    if (coeffs->nY > coeffs->nX) {
     
    355369    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly);
    356370
    357     for (x=0;x<input->numRows;x++) {
    358         for (y=0;y<input->numCols;y++) {
     371    for (x = 0; x < input->numRows; x++) {
     372        for (y = 0; y < input->numCols; y++) {
    359373            polySum = 0.0;
    360             for (i=0;i<coeffs->nX;i++) {
    361                 for (j=0;j<coeffs->nY;j++) {
    362                     polySum+= psPolynomial1DEval(rScalingFactors[x], chebPolys[i]) *
    363                               psPolynomial1DEval(cScalingFactors[y], chebPolys[j]) *
    364                               coeffs->coeff[i][j];
     374            for (i = 0; i < coeffs->nX; i++) {
     375                for (j = 0; j < coeffs->nY; j++) {
     376                    polySum +=
     377                        psPolynomial1DEval
     378                        (rScalingFactors[x],
     379                         chebPolys[i]) *
     380                        psPolynomial1DEval(cScalingFactors[y], chebPolys[j]) * coeffs->coeff[i][j];
    365381
    366382                }
     
    370386    }
    371387
    372     // Free the Chebyshev polynomials that were created in this routine.
    373     for (i=0;i<maxChebyPoly;i++) {
     388    // Free the Chebyshev polynomials that were
     389    // created in this routine.
     390    for (i = 0; i < maxChebyPoly; i++) {
    374391        psFree(chebPolys[i]);
    375392    }
     
    377394
    378395    // Free some data
    379     for (i=0;i<coeffs->nX;i++) {
     396    for (i = 0; i < coeffs->nX; i++) {
    380397        psFree(sums[i]);
    381398    }
     
    384401    psFree(rScalingFactors);
    385402
    386     return(0);
    387 }
     403    return (0);
     404}
Note: See TracChangeset for help on using the changeset viewer.