IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2004, 2:32:53 PM (22 years ago)
Author:
gusciora
Message:

Lots of bug fixes and such.

File:
1 edited

Legend:

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

    r831 r889  
    1919
    2020/// This routine must determine the various statistics for the image.
     21/*****************************************************************************
     22    GUS: verify that image/mask have the
     23 correct types
     24 sizes
     25 *****************************************************************************/
    2126psStats *psImageStats(psStats *stats,
    2227                      psImage *in,
     
    2631    psVector *junkData=NULL;
    2732    psVector *junkMask=NULL;
     33    int ptr = 0;
     34    int i = 0;
     35    int j = 0;
    2836
    2937    junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type);
    30     junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type);
    31 
    32     // GUS: figure out mask types
    33     junkData->data.F32 = (float *) in->data.F32;
    34     junkMask->data.F32 = (float *) mask->data.F32;
    35     stats = psVectorStats(stats, junkData, junkMask, maskVal);
     38    junkData->n = junkData->nalloc;
     39    ptr=0;
     40    for (i=0;i<in->numRows;i++) {
     41        for (j=0;j<in->numCols;j++) {
     42            junkData->data.F32[ptr++] = in->data.F32[i][j];
     43        }
     44    }
     45
     46    if (mask != NULL) {
     47        // GUS: verify that mask data is PS_TYPE_U8.
     48        // GUS: figure out mask types
     49
     50        junkMask = psVectorAlloc(mask->numRows * mask->numCols,
     51                                 mask->type.type);
     52        junkMask->n = junkMask->nalloc;
     53        // GUS: Is there a more efficient way to do this?
     54        ptr=0;
     55        for (i=0;i<mask->numRows;i++) {
     56            for (j=0;j<mask->numCols;j++) {
     57                junkMask->data.U8[ptr++] = mask->data.U8[i][j];
     58            }
     59        }
     60
     61        stats = psVectorStats(stats, junkData, junkMask, maskVal);
     62        psVectorFree(junkMask);
     63    } else {
     64        stats = psVectorStats(stats, junkData, NULL, 0);
     65    }
    3666
    3767    psVectorFree(junkData);
    38     psVectorFree(junkMask);
    3968
    4069    return(stats);
     
    4473    NOTE: We assume that the psHistogram structure out has already been
    4574    allocated and initialized.
     75 
     76    GUS: verify that image/mask have the
     77 correct types
     78 sizes
    4679 *****************************************************************************/
    4780psHistogram *psImageHistogram(psHistogram *out,
     
    5285    psVector *junkData=NULL;
    5386    psVector *junkMask=NULL;
     87    int ptr = 0;
     88    int i = 0;
     89    int j = 0;
    5490
    5591    junkData = psVectorAlloc(in->numRows * in->numCols, in->type.type);
    56     junkMask = psVectorAlloc(mask->numRows * mask->numCols, mask->type.type);
    57 
    58     // GUS: figure out mask types
    59     junkData->data.F32 = (float *) in->data.F32;
    60     junkMask->data.F32 = (float *) mask->data.F32;
    61 
    62     out = psHistogramVector(out, junkData, junkMask, maskVal);
    63 
     92    junkData->n = junkData->nalloc;
     93
     94    // GUS: Is there a more efficient way to do this?  memcopy() won't work.
     95    // Can we trick the junkData structure to use the image buffer, then
     96    // untrick it before we deallocate it (so we won't deallocate that buffer
     97    // twice?
     98
     99    // GUS: Make sure you have the numRows/NumCols in the right place.
     100    ptr=0;
     101    for (i=0;i<in->numRows;i++) {
     102        for (j=0;j<in->numCols;j++) {
     103            junkData->data.F32[ptr++] = in->data.F32[i][j];
     104        }
     105    }
     106
     107    if (mask != NULL) {
     108        // GUS: verify that mask data is PS_TYPE_U8.
     109        // GUS: figure out mask types
     110
     111        junkMask = psVectorAlloc(mask->numRows * mask->numCols,
     112                                 mask->type.type);
     113        junkMask->n = junkMask->nalloc;
     114
     115        // GUS: Is there a more efficient way to do this?
     116        ptr=0;
     117        for (i=0;i<mask->numRows;i++) {
     118            for (j=0;j<mask->numCols;j++) {
     119                junkMask->data.U8[ptr++] = mask->data.U8[i][j];
     120            }
     121        }
     122        out = psHistogramVector(out, junkData, junkMask, maskVal);
     123        psVectorFree(junkMask);
     124    } else {
     125        out = psHistogramVector(out, junkData, NULL, 0);
     126    }
    64127    psVectorFree(junkData);
    65     psVectorFree(junkMask);
    66128
    67129    return(out);
     
    91153    int maxChebyPoly = 0;
    92154
     155
    93156    // Create the sums[][] data structure.  This will hold the LHS of equation
    94157    // 29 in the ADD: sums[k][l] = SUM { image(x,y) * Tk(x) * Tl(y) }
     158
    95159    sums = (float **) psAlloc(coeffs->nX * sizeof(float *));
    96160    for (i=0;i<coeffs->nX;i++) {
     
    105169    // Determine how many Chebyshev polynomials are needed, then create them.
    106170    maxChebyPoly = coeffs->nX;
    107     if (coeffs->nX > coeffs->nY) {
     171    if (coeffs->nY > coeffs->nX) {
    108172        maxChebyPoly = coeffs->nY;
    109173    }
     
    133197                                 psEvalPolynomial1D((float) x, chebPolys[i]) *
    134198                                 psEvalPolynomial1D((float) y, chebPolys[j]);
     199
    135200                }
    136201            }
     
    160225    }
    161226
    162 
    163227    // Free the Chebyshev polynomials that were created in this routine.
    164228    for (i=0;i<maxChebyPoly;i++) {
    165         psFree(chebPolys[i]);
    166     }
     229        psPolynomial1DFree(chebPolys[i]);
     230    }
     231    psFree(chebPolys);
     232
     233    // Free some data
     234    for (i=0;i<coeffs->nX;i++) {
     235        psFree(sums[i]);
     236    }
     237    psFree(sums);
    167238
    168239    return(coeffs);
     
    199270    // Determine how many Chebyshev polynomials are needed, then create them.
    200271    maxChebyPoly = coeffs->nX;
    201     if (coeffs->nX > coeffs->nY) {
     272    if (coeffs->nY > coeffs->nX) {
    202273        maxChebyPoly = coeffs->nY;
    203274    }
     
    219290        }
    220291    }
    221 
    222292
    223293    for (x=0;x<input->numRows;x++) {
     
    227297                for (j=0;j<coeffs->nY;j++) {
    228298                    polySum+= psEvalPolynomial1D((float)x, chebPolys[i]) *
    229                               psEvalPolynomial1D((float)y, chebPolys[y]) *
     299                              psEvalPolynomial1D((float)y, chebPolys[j]) *
    230300                              coeffs->coeff[i][j];
    231 
    232301                }
    233302            }
     
    236305    }
    237306
    238 
    239307    // Free the Chebyshev polynomials that were created in this routine.
    240308    for (i=0;i<maxChebyPoly;i++) {
    241         psFree(chebPolys[i]);
    242     }
     309        psPolynomial1DFree(chebPolys[i]);
     310    }
     311    psFree(chebPolys);
     312
     313    // Free some data
     314    for (i=0;i<coeffs->nX;i++) {
     315        psFree(sums[i]);
     316    }
     317    psFree(sums);
    243318
    244319    return(0);
Note: See TracChangeset for help on using the changeset viewer.