Index: trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- trunk/psLib/src/imageops/psImageStats.c	(revision 5136)
+++ trunk/psLib/src/imageops/psImageStats.c	(revision 5137)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.80 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-22 22:49:29 $
+ *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-26 22:35:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -638,16 +638,73 @@
 // count number of pixels with given mask value
 long psImageCountPixelMask (psImage *mask,
+                            psRegion region,
                             psMaskType value)
 {
     long Npixels = 0;
-
-    for (long i = 0; i < mask->numRows; i++) {
-        for (long j = 0; j < mask->numCols; j++) {
-            if (mask->data.U8[i][j] & value) {
-                Npixels ++;
-            }
-        }
+    int x0 = 0;
+    int y0 = 0;
+    int x1 = 0;
+    int y1 = 0;
+    psElemType type;
+    if (mask == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psImage_IMAGE_NULL);
+        return -1;
+    }
+    if (region.x1 > mask->numCols || region.y1 > mask->numRows) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "psRegion input is outside of image boundary\n");
+        return -1;
+    }
+    if (region.x0 <= 0 || region.x1 <= 0 || region.y0 <= 0 || region.y1 <= 0) {
+        region = psRegionForImage(mask, region);
+    }
+    if (region.x0 > region.x1 || region.y0 > region.y1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "Invalid region.  Lower boundary greater than upper boundary.\n");
+        return -1;
+    }
+    if (region.x0 == region.x1 || region.y0 == region.y1) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "psRegion input contains 0 pixels\n");
+        return -1;
+    }
+
+    x0 = (int)(roundf(region.x0));
+    x1 = (int)(roundf(region.x1));
+    y0 = (int)(roundf(region.y0));
+    y1 = (int)(roundf(region.y1));
+
+    type = mask->type.type;
+
+    switch (type) {
+    case PS_TYPE_U8:
+        for (long i = x0; i < x1; i++) {
+            for (long j = y0; j < y1; j++) {
+                if (mask->data.U8[i][j] & value) {
+                    Npixels ++;
+                }
+            }
+        }
+        break;
+    case PS_TYPE_S8:
+    case PS_TYPE_S16:
+    case PS_TYPE_S32:
+    case PS_TYPE_S64:
+    case PS_TYPE_U16:
+    case PS_TYPE_U32:
+    case PS_TYPE_U64:
+    case PS_TYPE_F32:
+    case PS_TYPE_F64:
+    case PS_TYPE_C32:
+    case PS_TYPE_C64:
+    default:
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE, type, PS_TYPE_U8);
+        return -1;
     }
     return (Npixels);
-}
-
+
+
+}
+
Index: trunk/psLib/src/imageops/psImageStats.h
===================================================================
--- trunk/psLib/src/imageops/psImageStats.h	(revision 5136)
+++ trunk/psLib/src/imageops/psImageStats.h	(revision 5137)
@@ -9,6 +9,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-22 02:32:00 $
+*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-09-26 22:35:53 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -85,7 +85,15 @@
 );
 
+/** Returns the number of pixels in the image region which satisfy any of the mask bits.
+ *
+ *  An error (eg, invalid image, invalid region) results in a return value of -1.
+ *  The vector must be U8.
+ *
+ *  @return long:       the number of pixels counted
+ */
 long psImageCountPixelMask(
-    psImage *mask,
-    psMaskType value
+    psImage *mask,                     ///< input image to count
+    psRegion region,                   ///< input region of image
+    psMaskType value                   ///< the mask value to satisfy
 );
 
Index: trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- trunk/psLib/src/mathtypes/psImage.h	(revision 5136)
+++ trunk/psLib/src/mathtypes/psImage.h	(revision 5137)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.71 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-23 00:04:36 $
+ *  @version $Revision: 1.72 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-26 22:35:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -109,5 +109,4 @@
 ;
 
-
 /** Checks the type of a particular pointer.
  *
Index: trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- trunk/psLib/src/mathtypes/psVector.c	(revision 5136)
+++ trunk/psLib/src/mathtypes/psVector.c	(revision 5137)
@@ -9,6 +9,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-09-24 00:17:44 $
+*  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-09-26 22:35:53 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -948,2 +948,43 @@
 }
 
+// count number of pixels with given mask value
+long psVectorCountPixelMask (psVector *mask,
+                             psMaskType value)
+{
+    long Npixels = 0;
+    if (mask == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psVector_NULL);
+        Npixels = -1;
+        return Npixels;
+    }
+
+    psElemType type;
+    type = mask->type.type;
+
+    switch (type) {
+    case PS_TYPE_U8:
+        for (long i = 0; i < mask->n; i++) {
+            if (mask->data.U8[i] & value) {
+                Npixels ++;
+            }
+        }
+        break;
+    case PS_TYPE_S8:
+    case PS_TYPE_S16:
+    case PS_TYPE_S32:
+    case PS_TYPE_S64:
+    case PS_TYPE_U16:
+    case PS_TYPE_U32:
+    case PS_TYPE_U64:
+    case PS_TYPE_F32:
+    case PS_TYPE_F64:
+    case PS_TYPE_C32:
+    case PS_TYPE_C64:
+    default:
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, type);
+        return -1;
+    }
+    return (Npixels);
+}
+
Index: trunk/psLib/src/mathtypes/psVector.h
===================================================================
--- trunk/psLib/src/mathtypes/psVector.h	(revision 5136)
+++ trunk/psLib/src/mathtypes/psVector.h	(revision 5137)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-24 00:17:44 $
+ *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-26 22:35:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -247,4 +247,15 @@
 );
 
+/** Returns the number of pixels in the vector which satisfy any of the mask bits.
+ *
+ *  An error (eg, invalid vector) results in a return value of -1.  The vector must be U8.
+ *
+ *  @return long:       the number of pixels counted
+ */
+long psVectorCountPixelMask(
+    psVector *mask,                    ///< input vector to count
+    psMaskType value                   ///< the mask value to satisfy
+);
+
 /// @}
 
Index: trunk/psLib/src/types/psPixels.c
===================================================================
--- trunk/psLib/src/types/psPixels.c	(revision 5136)
+++ trunk/psLib/src/types/psPixels.c	(revision 5137)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-24 00:17:44 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-26 22:35:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -345,6 +345,7 @@
         return false;
     }
-    if(position < 0)
+    if(position < 0) {
         position += pixels->n;
+    }
     if(position < 0) {
         psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Negative number too large\n");
@@ -382,6 +383,7 @@
         return out;
     }
-    if (position < 0)
+    if (position < 0) {
         position += pixels->n;
+    }
     if (position < 0) {
         psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Negative number too large\n");
Index: trunk/psLib/src/types/psPixels.h
===================================================================
--- trunk/psLib/src/types/psPixels.h	(revision 5136)
+++ trunk/psLib/src/types/psPixels.h	(revision 5137)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-24 00:17:44 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-26 22:35:53 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
