Index: trunk/psModules/src/pmObjects.c
===================================================================
--- trunk/psModules/src/pmObjects.c	(revision 3701)
+++ trunk/psModules/src/pmObjects.c	(revision 3717)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-04-14 03:27:50 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-04-19 22:58:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -45,5 +45,5 @@
     tmp->y = 0.0;
     tmp->Sx = 0.0;
-    tmp->Sx = 0.0;
+    tmp->Sy = 0.0;
     tmp->Sxy = 0.0;
     tmp->Sum = 0.0;
@@ -325,4 +325,5 @@
         psError(PS_ERR_UNKNOWN, true, "Currently, input image must have at least 2 rows and 2 columns.");
     }
+    psPeakType myPeakClass = PM_PEAK_UNDEF;
     psVector *tmpRow = NULL;
     psU32 col = 0;
@@ -343,33 +344,51 @@
         //
         if (col == 0) {
-            if ( (image->data.F32[row][col] >  image->data.F32[row][col+1]) &&
+            if ( (image->data.F32[row][col] > threshold) &&
+                    (image->data.F32[row][col] >  image->data.F32[row][col+1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row+1][col]) &&
                     (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {
-                if (image->data.F32[row][col] > threshold) {
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], PM_PEAK_EDGE);
+                myPeakClass = PM_PEAK_EDGE;
+                if (image->data.F32[row][col] > image->data.F32[row+1][col+1]) {
+                    myPeakClass|= PM_PEAK_LONE;
+                } else {
+                    myPeakClass|= PM_PEAK_FLAT;
                 }
+                list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
             }
         } else if (col < (image->numCols - 1)) {
-            if ( (image->data.F32[row][col] >= image->data.F32[row][col-1]) &&
+            if ( (image->data.F32[row][col] > threshold) &&
+                    (image->data.F32[row][col] >= image->data.F32[row][col-1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row][col+1]) &&
                     (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row+1][col]) &&
                     (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {
-                if (image->data.F32[row][col] > threshold) {
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], PM_PEAK_EDGE);
+
+                myPeakClass = PM_PEAK_EDGE;
+                if ( (image->data.F32[row][col] > image->data.F32[row][col-1]) &&
+                        (image->data.F32[row][col] > image->data.F32[row+1][col-1]) &&
+                        (image->data.F32[row][col] > image->data.F32[row+1][col+1])) {
+                    myPeakClass|= PM_PEAK_LONE;
+                } else {
+                    myPeakClass|= PM_PEAK_FLAT;
                 }
+                list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
             }
 
         } else if (col == (image->numCols - 1)) {
-            if ( (image->data.F32[row][col] >= image->data.F32[row][col-1]) &&
+            if ( (image->data.F32[row][col] > threshold) &&
+                    (image->data.F32[row][col] >= image->data.F32[row][col-1]) &&
                     (image->data.F32[row][col] > image->data.F32[row+1][col]) &&
                     (image->data.F32[row][col] >= image->data.F32[row+1][col-1])) {
-                if (image->data.F32[row][col] > threshold) {
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], PM_PEAK_EDGE);
+                myPeakClass = PM_PEAK_EDGE;
+                if ( (image->data.F32[row][col] > image->data.F32[row][col-1]) &&
+                        (image->data.F32[row][col] > image->data.F32[row+1][col-1])) {
+                    myPeakClass|= PM_PEAK_LONE;
+                } else {
+                    myPeakClass|= PM_PEAK_FLAT;
                 }
+                list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
             }
-
         } else {
-            psError(PS_ERR_UNKNOWN, true, "peak specified valid column range.");
+            psError(PS_ERR_UNKNOWN, true, "peak specified outside valid column range.");
         }
     }
@@ -390,20 +409,30 @@
         // Step through all local peaks in this row.
         for (psU32 i = 0 ; i < row1->n ; i++ ) {
-            psPeakType myType = PM_PEAK_UNDEF;
             col = row1->data.U32[i];
 
             if (col == 0) {
                 // If col==0, then we can not read col-1 pixels
-                if ((image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
+                if ((image->data.F32[row][col] > threshold) &&
+                        (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
                         (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&
                         (image->data.F32[row][col] >= image->data.F32[row][col+1]) &&
                         (image->data.F32[row][col] >= image->data.F32[row+1][col]) &&
                         (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {
-                    myType = PM_PEAK_EDGE;
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], myType);
+
+                    myPeakClass = PM_PEAK_EDGE;
+                    if ((image->data.F32[row][col] > image->data.F32[row-1][col+1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row][col+1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col+1])) {
+                        myPeakClass|= PM_PEAK_LONE;
+                    } else {
+                        myPeakClass|= PM_PEAK_FLAT;
+                    }
+                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
                 }
             } else if (col < (image->numCols - 1)) {
                 // This is an interior pixel
-                if ((image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
+                if ((image->data.F32[row][col] > threshold) &&
+                        (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
                         (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
                         (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&
@@ -413,33 +442,22 @@
                         (image->data.F32[row][col] >= image->data.F32[row+1][col]) &&
                         (image->data.F32[row][col] >= image->data.F32[row+1][col+1])) {
-                    if (image->data.F32[row][col] > threshold) {
-                        if ((image->data.F32[row][col] > image->data.F32[row-1][col-1]) &&
-                                (image->data.F32[row][col] > image->data.F32[row-1][col]) &&
-                                (image->data.F32[row][col] > image->data.F32[row-1][col+1]) &&
-                                (image->data.F32[row][col] > image->data.F32[row][col-1]) &&
-                                (image->data.F32[row][col] > image->data.F32[row][col+1]) &&
-                                (image->data.F32[row][col] > image->data.F32[row+1][col-1]) &&
-                                (image->data.F32[row][col] > image->data.F32[row+1][col]) &&
-                                (image->data.F32[row][col] > image->data.F32[row+1][col+1])) {
-                            myType = PM_PEAK_LONE;
-                        }
-
-                        if ((image->data.F32[row][col] == image->data.F32[row-1][col-1]) ||
-                                (image->data.F32[row][col] == image->data.F32[row-1][col]) ||
-                                (image->data.F32[row][col] == image->data.F32[row-1][col+1]) ||
-                                (image->data.F32[row][col] == image->data.F32[row][col-1]) ||
-                                (image->data.F32[row][col] == image->data.F32[row][col+1]) ||
-                                (image->data.F32[row][col] == image->data.F32[row+1][col-1]) ||
-                                (image->data.F32[row][col] == image->data.F32[row+1][col]) ||
-                                (image->data.F32[row][col] == image->data.F32[row+1][col+1])) {
-                            myType = PM_PEAK_FLAT;
-                        }
-
-                        list = MyListAddPeak(list, col, row, image->data.F32[row][col], myType);
+
+                    if ((image->data.F32[row][col] > image->data.F32[row-1][col-1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row-1][col+1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row][col+1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col-1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col+1])) {
+                        myPeakClass = PM_PEAK_LONE;
+                    } else {
+                        myPeakClass = PM_PEAK_FLAT;
                     }
+
+                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
                 }
             } else if (col == (image->numCols - 1)) {
                 // If col==numCols - 1, then we can not read col+1 pixels
-                if ((image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
+                if ((image->data.F32[row][col] > threshold) &&
+                        (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
                         (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
                         (image->data.F32[row][col] > image->data.F32[row][col-1]) &&
@@ -447,11 +465,19 @@
                         (image->data.F32[row][col] >= image->data.F32[row+1][col-1]) &&
                         (image->data.F32[row][col] >= image->data.F32[row+1][col])) {
-                    myType = PM_PEAK_EDGE;
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], myType);
+
+                    myPeakClass = PM_PEAK_EDGE;
+                    if ((image->data.F32[row][col] > image->data.F32[row-1][col-1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row][col+1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col-1]) &&
+                            (image->data.F32[row][col] > image->data.F32[row+1][col])) {
+                        myPeakClass|= PM_PEAK_LONE;
+                    } else {
+                        myPeakClass|= PM_PEAK_FLAT;
+                    }
+                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
                 }
             } else {
-                psError(PS_ERR_UNKNOWN, true, "peak specified valid column range.");
+                psError(PS_ERR_UNKNOWN, true, "peak specified outside valid column range.");
             }
-
         }
     }
@@ -466,29 +492,52 @@
         col = row1->data.U32[i];
         if (col == 0) {
-            if ( (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
+            if ( (image->data.F32[row][col] > threshold) &&
+                    (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
                     (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row][col+1])) {
-                if (image->data.F32[row][col] > threshold) {
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], PM_PEAK_EDGE);
+
+                myPeakClass = PM_PEAK_EDGE;
+                if (image->data.F32[row][col] > image->data.F32[row-1][col+1]) {
+                    myPeakClass|= PM_PEAK_LONE;
+                } else {
+                    myPeakClass|= PM_PEAK_FLAT;
                 }
+
+                list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
             }
         } else if (col < (image->numCols - 1)) {
-            if ( (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
+            if ( (image->data.F32[row][col] > threshold) &&
+                    (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
                     (image->data.F32[row][col] >= image->data.F32[row-1][col+1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row][col-1]) &&
                     (image->data.F32[row][col] >= image->data.F32[row][col+1])) {
-                if (image->data.F32[row][col] > threshold) {
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], PM_PEAK_EDGE);
+
+                myPeakClass = PM_PEAK_EDGE;
+                if ( (image->data.F32[row][col] > image->data.F32[row-1][col-1]) &&
+                        (image->data.F32[row][col] > image->data.F32[row-1][col+1]) &&
+                        (image->data.F32[row][col] > image->data.F32[row][col+1])) {
+                    myPeakClass|= PM_PEAK_LONE;
+                } else {
+                    myPeakClass|= PM_PEAK_FLAT;
                 }
+
+                list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
             }
 
         } else if (col == (image->numCols - 1)) {
-            if ( (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
+            if ( (image->data.F32[row][col] > threshold) &&
+                    (image->data.F32[row][col] >= image->data.F32[row-1][col-1]) &&
                     (image->data.F32[row][col] >  image->data.F32[row-1][col]) &&
                     (image->data.F32[row][col] >  image->data.F32[row][col-1])) {
-                if (image->data.F32[row][col] > threshold) {
-                    list = MyListAddPeak(list, col, row, image->data.F32[row][col], PM_PEAK_EDGE);
+
+                myPeakClass = PM_PEAK_EDGE;
+                if (image->data.F32[row][col] > image->data.F32[row-1][col-1]) {
+                    myPeakClass|= PM_PEAK_LONE;
+                } else {
+                    myPeakClass|= PM_PEAK_FLAT;
                 }
+
+                list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass);
             }
         } else {
@@ -600,8 +649,8 @@
     psS32 SubImageCenterRow = peak->y;
     psS32 SubImageCenterCol = peak->x;
-    psS32 SubImageStartRow = SubImageCenterRow - outerRadiusS32;
-    psS32 SubImageEndRow = SubImageCenterRow + outerRadiusS32;
-    psS32 SubImageStartCol = SubImageCenterCol - outerRadiusS32;
-    psS32 SubImageEndCol = SubImageCenterCol + outerRadiusS32;
+    psS32 SubImageStartRow = PS_MAX(SubImageCenterRow - outerRadiusS32, 0);
+    psS32 SubImageEndRow =   PS_MIN(SubImageCenterRow + outerRadiusS32, image->numRows - 1);
+    psS32 SubImageStartCol = PS_MAX(SubImageCenterCol - outerRadiusS32, 0);
+    psS32 SubImageEndCol =   PS_MIN(SubImageCenterCol + outerRadiusS32, image->numCols - 1);
     // AnulusWidth == number of pixels width in the annulus.  We add one since
     // the pixels at the inner AND outher radius are included.
