Index: /trunk/psLib/src/imageops/psImageBackground.c
===================================================================
--- /trunk/psLib/src/imageops/psImageBackground.c	(revision 10395)
+++ /trunk/psLib/src/imageops/psImageBackground.c	(revision 10396)
@@ -13,6 +13,5 @@
 // XXX allow the user to choose the stats method?
 // (SAMPLE_MEAN, CLIPPED_MEAN, ROBUST_MEDIAN, FITTED_MEAN)
-psStats *psImageBackground(const psImage *image, const psImage *mask, psMaskType maskValue,
-                           double fmin, double fmax, long nMax, psStatsOptions option, psRandom *rng)
+bool psImageBackground(psStats *stats, const psImage *image, const psImage *mask, psMaskType maskValue, psRandom *rng)
 {
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
@@ -22,9 +21,11 @@
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, NULL);
     }
-    PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(fmin, 0.0, NULL);
-    PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(fmax, 0.0, NULL);
-    PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(fmin, 1.0, NULL);
-    PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(fmax, 1.0, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(nMax, NULL);
+    if (stats->options & PS_STAT_ROBUST_QUARTILE) {
+        PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(stats->min, 0.0, NULL);
+        PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(stats->max, 0.0, NULL);
+        PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(stats->min, 1.0, NULL);
+        PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(stats->max, 1.0, NULL);
+    }
+    PS_ASSERT_INT_NONNEGATIVE(stats->nSubsample, NULL);
     PS_ASSERT_PTR_NON_NULL(rng, NULL);
 
@@ -34,5 +35,5 @@
 
     const int Npixels = nx*ny;                // Total number of pixels
-    const int Nsubset = (nMax == 0) ? Npixels : PS_MIN(nMax, Npixels); // Number of pixels in subset
+    const int Nsubset = (stats->nSubsample == 0) ? Npixels : PS_MIN(stats->nSubsample, Npixels); // Number of pixels in subset
 
     psVector *values = psVectorAllocEmpty(Nsubset, PS_TYPE_F32); // Vector containing subsample
@@ -62,12 +63,10 @@
     values->n = n;
 
-    psStats *stats = psStatsAlloc(option); // Statistics, for return
-
     if (stats->options & PS_STAT_ROBUST_QUARTILE) {
         // use simple stats code (old verions)
         // XXX this hack is just for testing, drop when I am happy with the psStats version of the values
 
-        int imin = fmin * n;
-        int imax = fmax * n;
+        int imin = stats->min * n;
+        int imax = stats->max * n;
         int npts = imax - imin + 1;
 
Index: /trunk/psLib/src/imageops/psImageBackground.h
===================================================================
--- /trunk/psLib/src/imageops/psImageBackground.h	(revision 10395)
+++ /trunk/psLib/src/imageops/psImageBackground.h	(revision 10396)
@@ -7,13 +7,10 @@
 
 // Get the background for an image
-psStats *psImageBackground(const psImage *image, // Image for which to get the background
-                           const psImage *mask, // Mask image
-                           psMaskType maskValue, // Mask pixels which this mask value
-                           double fmin, // Fraction to return in the lower quartile field (0.25 for LQ)
-                           double fmax, // Fraction to return in the upper quartile field (0.75 for LQ)
-                           long nMax,   // Maximum number of pixels to subsample
-                           psStatsOptions option,
-                           psRandom *rng // Random number generator (for pixel selection)
-                          );
+bool psImageBackground(psStats *stats, // desired measurement and options
+                       const psImage *image, // Image for which to get the background
+                       const psImage *mask, // Mask image
+                       psMaskType maskValue, // Mask pixels which this mask value
+                       psRandom *rng // Random number generator (for pixel selection)
+                      );
 
 #endif // #ifndef PS_IMAGE_BACKGROUND_H
