IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 26, 2005, 12:35:54 PM (21 years ago)
Author:
drobbin
Message:

Implemented, updated, fixed, debugged the CountPixelMask fxns and tests

Location:
trunk/psLib/src/imageops
Files:
2 edited

Legend:

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

    r5096 r5137  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.80 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-09-22 22:49:29 $
     11 *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-09-26 22:35:53 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    638638// count number of pixels with given mask value
    639639long psImageCountPixelMask (psImage *mask,
     640                            psRegion region,
    640641                            psMaskType value)
    641642{
    642643    long Npixels = 0;
    643 
    644     for (long i = 0; i < mask->numRows; i++) {
    645         for (long j = 0; j < mask->numCols; j++) {
    646             if (mask->data.U8[i][j] & value) {
    647                 Npixels ++;
    648             }
    649         }
     644    int x0 = 0;
     645    int y0 = 0;
     646    int x1 = 0;
     647    int y1 = 0;
     648    psElemType type;
     649    if (mask == NULL) {
     650        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     651                PS_ERRORTEXT_psImage_IMAGE_NULL);
     652        return -1;
     653    }
     654    if (region.x1 > mask->numCols || region.y1 > mask->numRows) {
     655        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     656                "psRegion input is outside of image boundary\n");
     657        return -1;
     658    }
     659    if (region.x0 <= 0 || region.x1 <= 0 || region.y0 <= 0 || region.y1 <= 0) {
     660        region = psRegionForImage(mask, region);
     661    }
     662    if (region.x0 > region.x1 || region.y0 > region.y1) {
     663        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     664                "Invalid region.  Lower boundary greater than upper boundary.\n");
     665        return -1;
     666    }
     667    if (region.x0 == region.x1 || region.y0 == region.y1) {
     668        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     669                "psRegion input contains 0 pixels\n");
     670        return -1;
     671    }
     672
     673    x0 = (int)(roundf(region.x0));
     674    x1 = (int)(roundf(region.x1));
     675    y0 = (int)(roundf(region.y0));
     676    y1 = (int)(roundf(region.y1));
     677
     678    type = mask->type.type;
     679
     680    switch (type) {
     681    case PS_TYPE_U8:
     682        for (long i = x0; i < x1; i++) {
     683            for (long j = y0; j < y1; j++) {
     684                if (mask->data.U8[i][j] & value) {
     685                    Npixels ++;
     686                }
     687            }
     688        }
     689        break;
     690    case PS_TYPE_S8:
     691    case PS_TYPE_S16:
     692    case PS_TYPE_S32:
     693    case PS_TYPE_S64:
     694    case PS_TYPE_U16:
     695    case PS_TYPE_U32:
     696    case PS_TYPE_U64:
     697    case PS_TYPE_F32:
     698    case PS_TYPE_F64:
     699    case PS_TYPE_C32:
     700    case PS_TYPE_C64:
     701    default:
     702        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     703                PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE, type, PS_TYPE_U8);
     704        return -1;
    650705    }
    651706    return (Npixels);
    652 }
    653 
     707
     708
     709}
     710
  • trunk/psLib/src/imageops/psImageStats.h

    r5089 r5137  
    99*  @author GLG, MHPCC
    1010*
    11 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2005-09-22 02:32:00 $
     11*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2005-09-26 22:35:53 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    8585);
    8686
     87/** Returns the number of pixels in the image region which satisfy any of the mask bits.
     88 *
     89 *  An error (eg, invalid image, invalid region) results in a return value of -1.
     90 *  The vector must be U8.
     91 *
     92 *  @return long:       the number of pixels counted
     93 */
    8794long psImageCountPixelMask(
    88     psImage *mask,
    89     psMaskType value
     95    psImage *mask,                     ///< input image to count
     96    psRegion region,                   ///< input region of image
     97    psMaskType value                   ///< the mask value to satisfy
    9098);
    9199
Note: See TracChangeset for help on using the changeset viewer.