Index: /trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 10025)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 10026)
@@ -165,9 +165,17 @@
         }
 
-        float target = histo->nums->data.F32[0] * powf(10.0, thresh); // Level to which histogram must fall
-        int index;
-        for (index = 0; histo->nums->data.F32[index] > target && index < histo->nums->n; index++)
-            ;
-        limit = histo->bounds->data.F32[index];
+        // Find the mode.  Since this is a Poisson distribution (more or less), this should also be the mean
+        // and variance.
+        int max = 0;                    // Index of the mode
+        for (int i = 0; i < histo->nums->n; i++) {
+            if (histo->nums->data.F32[i] > histo->nums->data.F32[max]) {
+                max = i;
+            }
+        }
+
+        // Since the mode is most likely zero, we add one to get something realistic.  Then "thresh" is
+        // negative, so we subtract instead of add.
+        limit = max + 1.0 - thresh * sqrtf((float)max + 1.0);
+
     } else {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
Index: /trunk/psModules/src/detrend/pmMaskBadPixels.h
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 10025)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 10026)
@@ -8,6 +8,6 @@
 /// @author Eugene Magnier, IfA
 ///
-/// @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2006-11-17 00:50:39 $
+/// @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2006-11-17 01:17:59 $
 ///
 /// Copyright 2004 Institute for Astronomy, University of Hawaii
@@ -51,7 +51,5 @@
 /// Bad pixels are identified from the suspect pixels image (accumulated over a large number of images).
 /// Pixels marked as suspect in more than "thresh" standard deviations from the mean are identified as bad
-/// pixels (output image).  If "thresh" is negative, it is interpreted as a (base 10) logarithm of the
-/// fraction by which the number of pixels marked that many times must drop compared to the number of pixels
-/// with zero.
+/// pixels (output image).  If "thresh" is negative, a Poisson is assumed.
 psImage *pmMaskIdentifyBadPixels(const psImage *suspects, ///< Accumulated suspect pixels image
                                  float thresh, ///< Threshold for bad pixel (standard deviations)
