IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 26, 2009, 8:40:07 PM (17 years ago)
Author:
eugene
Message:

incorporating changes from 16bit mask upgrades (eam_branch_20081230)

File:
1 edited

Legend:

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

    r12431 r21183  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2007-03-14 00:39:50 $
     11 *  @version $Revision: 1.107 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2009-01-27 06:39:37 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5353                      const psImage* in,
    5454                      const psImage* mask,
    55                       psMaskType maskVal)
     55                      psImageMaskType maskVal)
    5656{
    5757    psVector *junkData = NULL;
     
    6262    PS_ASSERT_IMAGE_NON_NULL(in, false)
    6363    if (mask != NULL) {
    64         PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, false);
     64        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
    6565        PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
    6666    }
     67
     68    if (in->parent == NULL) {
     69        // stuff the image data into a psVector struct.
     70        // XXX this is a bit hackish: does it save much time? (avoids a Nx*Ny alloc)
     71        junkData = (psVector *) psAlloc(sizeof(psVector));
     72        junkData->type = in->type;
     73        P_PSVECTOR_SET_NALLOC(junkData,in->numRows * in->numCols);
     74        junkData->n = junkData->nalloc;
     75        junkData->data.U8 = in->data.V[0];      // since psImage data is contiguous...
     76    } else {
     77        // image not necessarily contiguous
     78        int numRows = in->numRows;
     79        int numCols = in->numCols;
     80        int rowSize = numCols * (PSELEMTYPE_SIZEOF(in->type.type));
     81
     82        junkData = psVectorAlloc(numRows*numCols, in->type.type);
     83
     84        psU8* data = junkData->data.U8;
     85        for (int row = 0; row < numRows; row++) {
     86            memcpy(data, in->data.V[row], rowSize);
     87            data += rowSize;
     88        }
     89    }
     90
     91    if (mask != NULL) {
     92        // image not necessarily contiguous, generate a temp vector to hold the full image
     93        int numRows = mask->numRows;
     94        int numCols = mask->numCols;
     95
     96        junkMask = psVectorAlloc(numRows*numCols, PS_TYPE_VECTOR_MASK);
     97
     98        psVectorMaskType *data = junkMask->data.PS_TYPE_VECTOR_MASK_DATA;
     99        for (int row = 0, nVect = 0; row < numRows; row++) {
     100            for (int col = 0; col < numCols; col++, nVect++) {
     101                data[nVect] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[row][col] & maskVal);
     102            }
     103        }
     104    }
     105
     106    psVectorStats(stats, junkData, NULL, junkMask, 0xff);
     107
     108    psFree(junkMask);
     109    psFree(junkData);
     110    return true;
     111}
     112
     113/*****************************************************************************
     114NOTE: We assume that the psHistogram structure out has already been allocated
     115and initialized.
     116 *****************************************************************************/
     117bool psImageHistogram(psHistogram* out,
     118                              const psImage* in,
     119                              const psImage* mask,
     120                              psImageMaskType maskVal)
     121{
     122    PS_ASSERT_PTR_NON_NULL(out, false);
     123    PS_ASSERT_PTR_NON_NULL(in, false);
     124    if (mask != NULL) {
     125        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
     126        PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
     127    }
     128    psVector* junkData = NULL;
     129    psVector* junkMask = NULL;
    67130
    68131    if (in->parent == NULL) {
     
    89152
    90153    if (mask != NULL) {
    91         if (mask->parent == NULL) {
    92             // stuff the mask data into a psVector struct.
    93             junkMask = psAlloc(sizeof(psVector));
    94             junkMask->type = mask->type;
    95             P_PSVECTOR_SET_NALLOC(junkMask,mask->numRows * mask->numCols);
    96             junkMask->n = junkMask->nalloc;
    97             junkMask->data.U8 = mask->data.V[0];
    98         } else {
    99             // image not necessarily contiguous
    100             int numRows = mask->numRows;
    101             int numCols = mask->numCols;
    102             int rowSize = numCols * (PSELEMTYPE_SIZEOF(mask->type.type));
    103 
    104             junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
    105 
    106             psU8* data = junkMask->data.U8;
    107             for (int row = 0; row < numRows; row++) {
    108                 memcpy(data, mask->data.V[row], rowSize);
    109                 data += rowSize;
    110             }
    111         }
    112     }
    113 
    114     psVectorStats(stats, junkData, NULL, junkMask, maskVal);
    115 
    116     psFree(junkMask);
    117     psFree(junkData);
    118     return true;
    119 }
    120 
    121 /*****************************************************************************
    122 NOTE: We assume that the psHistogram structure out has already been allocated
    123 and initialized.
    124  *****************************************************************************/
    125 bool psImageHistogram(psHistogram* out,
    126                               const psImage* in,
    127                               const psImage* mask,
    128                               psMaskType maskVal)
    129 {
    130     PS_ASSERT_PTR_NON_NULL(out, false);
    131     PS_ASSERT_PTR_NON_NULL(in, false);
    132     if (mask != NULL) {
    133         PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, false);
    134         PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
    135     }
    136     psVector* junkData = NULL;
    137     psVector* junkMask = NULL;
    138 
    139     if (in->parent == NULL) {
    140         // stuff the image data into a psVector struct.
    141         junkData = (psVector *) psAlloc(sizeof(psVector));
    142         junkData->type = in->type;
    143         P_PSVECTOR_SET_NALLOC(junkData,in->numRows * in->numCols);
    144         junkData->n = junkData->nalloc;
    145         junkData->data.U8 = in->data.V[0];      // since psImage data is contiguous...
    146     } else {
    147         // image not necessarily contiguous
    148         int numRows = in->numRows;
    149         int numCols = in->numCols;
    150         int rowSize = numCols * (PSELEMTYPE_SIZEOF(in->type.type));
    151 
    152         junkData = psVectorAlloc(numRows*numCols, in->type.type);
    153 
    154         psU8* data = junkData->data.U8;
    155         for (int row = 0; row < numRows; row++) {
    156             memcpy(data, in->data.V[row], rowSize);
    157             data += rowSize;
    158         }
    159     }
    160 
    161     if (mask != NULL) {
    162         if (mask->parent == NULL) {
    163             // stuff the mask data into a psVector struct.
    164             junkMask = psAlloc(sizeof(psVector));
    165             junkMask->type = mask->type;
    166             P_PSVECTOR_SET_NALLOC(junkMask,mask->numRows * mask->numCols);
    167             junkMask->n = junkMask->nalloc;
    168             junkMask->data.U8 = mask->data.V[0];
    169         } else {
    170             // image not necessarily contiguous
    171             int numRows = mask->numRows;
    172             int numCols = mask->numCols;
    173             int rowSize = numCols * (PSELEMTYPE_SIZEOF(mask->type.type));
    174 
    175             junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
    176 
    177             psU8* data = junkMask->data.U8;
    178             for (int row = 0; row < numRows; row++) {
    179                 memcpy(data, mask->data.V[row], rowSize);
    180                 data += rowSize;
    181             }
    182         }
     154        // image not necessarily contiguous; vector & image mask types do not match
     155        int numRows = mask->numRows;
     156        int numCols = mask->numCols;
     157
     158        junkMask = psVectorAlloc(numRows*numCols, PS_TYPE_VECTOR_MASK);
     159
     160        psVectorMaskType *data = junkMask->data.PS_TYPE_VECTOR_MASK_DATA;
     161        for (int row = 0, nVect = 0; row < numRows; row++) {
     162            for (int col = 0; col < numCols; col++, nVect++) {
     163                data[nVect] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[row][col] & maskVal);
     164            }
     165        }
    183166    }
    184167
     
    472455long psImageCountPixelMask (psImage *mask,
    473456                            psRegion region,
    474                             psMaskType value)
     457                            psImageMaskType value)
    475458{
    476459    long Npixels = 0;
     
    479462    int x1 = 0;
    480463    int y1 = 0;
    481     psElemType type;
    482464
    483465    // this is not a valid error: a psRegion with ranges outside the valid pixels
     
    608590    y1 = row1;
    609591
    610     type = mask->type.type;
    611     if (type != PS_TYPE_MASK) {
    612         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    613                 "psImage type does not match the specified psMaskType!\n");
    614         return -1;
    615     }
    616 
     592# define PS_IMAGE_COUNT_PIXEL_MASK(NAME,TYPE) \
     593    case PS_TYPE_##NAME: \
     594        for (long j = y0; j < y1; j++) { \
     595            for (long i = x0; i < x1; i++) { \
     596                if (mask->data.TYPE[j][i] & value) { \
     597                    Npixels ++; \
     598                } \
     599            } \
     600        } \
     601        break;
     602
     603    psElemType type = mask->type.type;
    617604    switch (type) {
    618     case PS_TYPE_U8:
    619     case PS_TYPE_U16:
    620         for (long j = y0; j < y1; j++) {
    621             for (long i = x0; i < x1; i++) {
    622                 if (mask->data.PS_TYPE_MASK_DATA[j][i] & value) {
    623                     Npixels ++;
    624                 }
    625             }
    626         }
    627         break;
    628     case PS_TYPE_S8:
    629     case PS_TYPE_S16:
    630     case PS_TYPE_S32:
    631     case PS_TYPE_S64:
    632     case PS_TYPE_U32:
    633     case PS_TYPE_U64:
    634     case PS_TYPE_F32:
    635     case PS_TYPE_F64:
     605        PS_IMAGE_COUNT_PIXEL_MASK(U8, U8);
     606        PS_IMAGE_COUNT_PIXEL_MASK(U16,U16);
     607        PS_IMAGE_COUNT_PIXEL_MASK(U32,U32);
     608        PS_IMAGE_COUNT_PIXEL_MASK(U64,U64);
     609        PS_IMAGE_COUNT_PIXEL_MASK(S8, S8);
     610        PS_IMAGE_COUNT_PIXEL_MASK(S16,S16);
     611        PS_IMAGE_COUNT_PIXEL_MASK(S32,S32);
     612        PS_IMAGE_COUNT_PIXEL_MASK(S64,S64);
     613
    636614    default:
    637615        // XXX this should include the mask type (as a string)
    638616        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    639                 _("Input psImage mask type is not a supported mask datatype"));
     617                _("Input psImage is an unsupported datatype"));
    640618
    641619        return -1;
Note: See TracChangeset for help on using the changeset viewer.