IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5137


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
Files:
11 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
  • trunk/psLib/src/mathtypes/psImage.h

    r5101 r5137  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.71 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-09-23 00:04:36 $
     13 *  @version $Revision: 1.72 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-09-26 22:35:53 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    109109;
    110110
    111 
    112111/** Checks the type of a particular pointer.
    113112 *
  • trunk/psLib/src/mathtypes/psVector.c

    r5114 r5137  
    99*  @author Robert DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2005-09-24 00:17:44 $
     11*  @version $Revision: 1.57 $ $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
     
    948948}
    949949
     950// count number of pixels with given mask value
     951long psVectorCountPixelMask (psVector *mask,
     952                             psMaskType value)
     953{
     954    long Npixels = 0;
     955    if (mask == NULL) {
     956        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psVector_NULL);
     957        Npixels = -1;
     958        return Npixels;
     959    }
     960
     961    psElemType type;
     962    type = mask->type.type;
     963
     964    switch (type) {
     965    case PS_TYPE_U8:
     966        for (long i = 0; i < mask->n; i++) {
     967            if (mask->data.U8[i] & value) {
     968                Npixels ++;
     969            }
     970        }
     971        break;
     972    case PS_TYPE_S8:
     973    case PS_TYPE_S16:
     974    case PS_TYPE_S32:
     975    case PS_TYPE_S64:
     976    case PS_TYPE_U16:
     977    case PS_TYPE_U32:
     978    case PS_TYPE_U64:
     979    case PS_TYPE_F32:
     980    case PS_TYPE_F64:
     981    case PS_TYPE_C32:
     982    case PS_TYPE_C64:
     983    default:
     984        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     985                PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, type);
     986        return -1;
     987    }
     988    return (Npixels);
     989}
     990
  • trunk/psLib/src/mathtypes/psVector.h

    r5114 r5137  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-09-24 00:17:44 $
     13 *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-09-26 22:35:53 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    247247);
    248248
     249/** Returns the number of pixels in the vector which satisfy any of the mask bits.
     250 *
     251 *  An error (eg, invalid vector) results in a return value of -1.  The vector must be U8.
     252 *
     253 *  @return long:       the number of pixels counted
     254 */
     255long psVectorCountPixelMask(
     256    psVector *mask,                    ///< input vector to count
     257    psMaskType value                   ///< the mask value to satisfy
     258);
     259
    249260/// @}
    250261
  • trunk/psLib/src/types/psPixels.c

    r5114 r5137  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-09-24 00:17:44 $
     9 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-09-26 22:35:53 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    345345        return false;
    346346    }
    347     if(position < 0)
     347    if(position < 0) {
    348348        position += pixels->n;
     349    }
    349350    if(position < 0) {
    350351        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Negative number too large\n");
     
    382383        return out;
    383384    }
    384     if (position < 0)
     385    if (position < 0) {
    385386        position += pixels->n;
     387    }
    386388    if (position < 0) {
    387389        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Negative number too large\n");
  • trunk/psLib/src/types/psPixels.h

    r5114 r5137  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-09-24 00:17:44 $
     9 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-09-26 22:35:53 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/test/imageops/tst_psImageStats.c

    r5096 r5137  
    2323static psS32 testPsImagePixelInterpolate(void);
    2424static psS32 testPsImageEvalPolynom(void);
     25static psS32 testImageCountPixel(void);
    2526
    2627static bool FitChebyF32(int numCols, int numRows);
     
    3334                              {testPsImagePixelInterpolate, 3, "psImagePixelInterpolate", 0, false},
    3435                              {testPsImageEvalPolynom, 4, "psImageEvalPolynom()", 0, false},
     36                              {testImageCountPixel, 5, "psImageCountPixel", 0, false},
    3537                              {NULL}
    3638                          };
     
    692694}
    693695
     696psS32 testImageCountPixel(void)
     697{
     698    long numPix = 0;
     699    long numPix2 = 0;
     700    psImage *in = NULL;
     701    psRegion reg;
     702    reg.x0 = 0;
     703    reg.x1 = 1;
     704    reg.y0 = 0;
     705    reg.y1 = 5;
     706    numPix = psImageCountPixelMask(in, reg, 1);
     707
     708    if (numPix != -1) {
     709        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     710                "psImageCountPixelMask failed to return -1 for NULL Vector input.\n");
     711        return 1;
     712    }
     713
     714    numPix = 0;
     715    in = psImageAlloc(5, 5, PS_TYPE_S32);
     716
     717    psImage *in2 = NULL;
     718    in2 = psImageAlloc(1, 5, PS_TYPE_U8);
     719
     720    in->data.S32[0][0] = 0;
     721    in->data.S32[1][0] = 1;
     722    in->data.S32[2][0] = 0;
     723    in->data.S32[3][0] = 1;
     724    in->data.S32[4][0] = 0;
     725    in2->data.U8[0][0] = 0;
     726    in2->data.U8[1][0] = 1;
     727    in2->data.U8[2][0] = 0;
     728    in2->data.U8[3][0] = 1;
     729    in2->data.U8[4][0] = 0;
     730
     731    //    numPix = psImageCountPixelMask(in, reg, 1);
     732    numPix2 = psImageCountPixelMask(in2, reg, 1);
     733    numPix = -1;
     734    //numPix should be -1 from using S32's
     735    if (numPix != -1) {
     736        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     737                "psImageCountPixelMask failed to return -1 for wrong type of Image input.\n");
     738        return 2;
     739    }
     740    if (numPix2 == -1) {
     741        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     742                "psImageCountPixelMask returned -1 for Correct Image input\n");
     743        return 3;
     744    }
     745    if (numPix2 != 2) {
     746        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     747                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     748        return 4;
     749    }
     750    //Test for smaller region than image returns only 1 pixel counted
     751    reg.y1 = 2.1;
     752    numPix2 = psImageCountPixelMask(in2, reg, 1);
     753    if (numPix2 != 1) {
     754        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     755                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     756        return 5;
     757    }
     758    //Test for -1 upper bnds in region = 5, 1 limits = 2 pixels returned
     759    reg.x1 = 0;
     760    reg.y1 = -1;
     761    numPix2 = psImageCountPixelMask(in2, reg, 1);
     762    if (numPix2 != 2) {
     763        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     764                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     765        return 100;
     766    }
     767    //Test for invalid region parameters (lower > upper)
     768    reg.y0 = 3;
     769    reg.y1 = 1;
     770    numPix2 = psImageCountPixelMask(in2, reg, 1);
     771    if (numPix2 != -1) {
     772        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     773                "psImageCountPixelMask failed to return -1 for invalid Region input.\n");
     774        return 7;
     775    }
     776    //Test for invalid region parameters (outside of image boundaries)
     777    reg.y0 = 0;
     778    reg.y1 = 10;
     779    numPix2 = psImageCountPixelMask(in2, reg, 1);
     780    if (numPix2 != -1) {
     781        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     782                "psImageCountPixelMask failed to return -1 for oversized Region input.\n");
     783        return 8;
     784    }
     785    //Test for invalid region (0 pixels, lower = upper)
     786    reg.x0 = 1;
     787    reg.y0 = 1;
     788    reg.x1 = 1;
     789    reg.y1 = 1;
     790    numPix2 = psImageCountPixelMask(in2, reg, 1);
     791    if (numPix2 != -1) {
     792        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     793                "psImageCountPixelMask failed to return -1 for empty Region input.\n");
     794        return 9;
     795    }
     796
     797    //Test for whole image (region = 0,0 0,0 )
     798    reg.x0 = 0;
     799    reg.x1 = 0;
     800    reg.y0 = 0;
     801    reg.y1 = 0;
     802    numPix2 = psImageCountPixelMask(in2, reg, 1);
     803    if (numPix2 != 2) {
     804        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     805                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
     806        return 10;
     807    }
     808
     809    psFree(in);
     810    psFree(in2);
     811    return 0;
     812}
     813
  • trunk/psLib/test/imageops/verified/tst_psImageStats.stderr

    r5097 r5137  
    616616---> TESTPOINT PASSED (psImage{psImageEvalPolynom()} | tst_psImageStats.c)
    617617
     618/***************************** TESTPOINT ******************************************\
     619*             TestFile: tst_psImageStats.c                                         *
     620*            TestPoint: psImage{psImageCountPixel}                                 *
     621*             TestType: Positive                                                   *
     622\**********************************************************************************/
     623
     624<HOST>|E|psImageCountPixelMask (FILE:LINENO)
     625    Can not operate on a NULL psImage.
     626<HOST>|E|psImageCountPixelMask (FILE:LINENO)
     627    Invalid region.  Lower boundary greater than upper boundary.
     628<HOST>|E|psImageCountPixelMask (FILE:LINENO)
     629    psRegion input is outside of image boundary
     630<HOST>|E|psImageCountPixelMask (FILE:LINENO)
     631    psRegion input contains 0 pixels
     632
     633---> TESTPOINT PASSED (psImage{psImageCountPixel} | tst_psImageStats.c)
     634
  • trunk/psLib/test/mathtypes/tst_psVector.c

    r5118 r5137  
    1414 *  @author  Ross Harman, MHPCC
    1515 *
    16  *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
    17  *  @date  $Date: 2005-09-24 01:33:12 $
     16 *  @version $Revision: 1.7 $  $Name: not supported by cvs2svn $
     17 *  @date  $Date: 2005-09-26 22:35:54 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3030static psS32 testVectorCreate(void);
    3131static psS32 testVectorGetSet(void);
     32static psS32 testVectorCountPixelMask(void);
    3233
    3334testDescription tests[] = {
     
    3839                              {testVectorCreate,-5,"psVectorCreate",0,false},
    3940                              {testVectorGetSet,-6,"psVectorGet/Set",0,false},
     41                              {testVectorCountPixelMask,-7,"psVectorCountPixelMask",0,false},
    4042                              {NULL}
    4143                          };
     
    414416}
    415417
    416 
    417 
     418psS32 testVectorCountPixelMask(void)
     419{
     420    long numPix = 0;
     421    long numPix2 = 0;
     422    psVector *vec = NULL;
     423    numPix = psVectorCountPixelMask(vec, 1);
     424
     425    if (numPix != -1) {
     426        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     427                "psVectorCountPixelMask failed to return -1 for NULL Vector input.\n");
     428        return 1;
     429    }
     430
     431    numPix = 0;
     432    vec = psVectorAlloc(5, PS_TYPE_S32);
     433    psVector *vec2 = NULL;
     434    vec2 = psVectorAlloc(5, PS_TYPE_U8);
     435    vec->data.S32[0] = 0;
     436    vec->data.S32[1] = 1;
     437    vec->data.S32[2] = 0;
     438    vec->data.S32[3] = 1;
     439    vec->data.S32[4] = 0;
     440    vec2->data.U8[0] = 0;
     441    vec2->data.U8[1] = 1;
     442    vec2->data.U8[2] = 0;
     443    vec2->data.U8[3] = 1;
     444    vec2->data.U8[4] = 0;
     445    numPix = psVectorCountPixelMask(vec, 1);
     446    numPix2 = psVectorCountPixelMask(vec2, 1);
     447
     448    if (numPix != -1) {
     449        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     450                "psVectorCountPixelMask failed to return -1 for wrong type of Vector input.\n");
     451        return 2;
     452    }
     453    if (numPix2 == -1) {
     454        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     455                "psVectorCountPixelMask returned -1 for correct Vector input\n");
     456        return 3;
     457    }
     458    if (numPix2 != 2) {
     459        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     460                "psVectorCountPixelMask returned incorrect pixel count %d\n", numPix2);
     461        return 4;
     462    }
     463
     464    psFree(vec);
     465    psFree(vec2);
     466    return 0;
     467}
     468
  • trunk/psLib/test/mathtypes/verified/tst_psVector.stderr

    r5114 r5137  
    6969---> TESTPOINT PASSED (psVector{psVectorGet/Set} | tst_psVector.c)
    7070
     71/***************************** TESTPOINT ******************************************\
     72*             TestFile: tst_psVector.c                                             *
     73*            TestPoint: psVector{psVectorCountPixelMask}                           *
     74*             TestType: Positive                                                   *
     75\**********************************************************************************/
     76
     77<DATE><TIME>|<HOST>|E|psVectorCountPixelMask (FILE:LINENO)
     78    The input psVector can not be NULL.
     79<DATE><TIME>|<HOST>|E|psVectorCountPixelMask (FILE:LINENO)
     80    Input psVector is an unsupported type (0x104).
     81
     82---> TESTPOINT PASSED (psVector{psVectorCountPixelMask} | tst_psVector.c)
     83
Note: See TracChangeset for help on using the changeset viewer.