Index: /tags/ipp-20100610/ppStack/src/ppStackTarget.c
===================================================================
--- /tags/ipp-20100610/ppStack/src/ppStackTarget.c	(revision 28302)
+++ /tags/ipp-20100610/ppStack/src/ppStackTarget.c	(revision 28303)
@@ -164,8 +164,31 @@
 
         psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for background
+        float mean = NAN;                                  // Measured mean variance
         if (!psImageBackground(bg, NULL, variance, mask, maskVal, rng)) {
-            psError(PPSTACK_ERR_DATA, false, "Can't measure background for image.");
-            psFree(rng);
-            return NULL;
+            psErrorClear();
+            // Retry using all the available pixels
+            bg->nSubsample = variance->numCols * variance->numRows + 1;
+            if (!psImageStats(bg, variance, mask, maskVal)) {
+                psLogMsg("ppStack", PS_LOG_DETAIL,
+                         "Couldn't measure mean variance for image %d; retrying.", i);
+                psErrorClear();
+                // Retry with desperate statistic
+                bg->options = PS_STAT_SAMPLE_MEAN;
+                if (!psImageStats(bg, variance, mask, maskVal)) {
+                    psWarning("Unable to measure mean variance for image %d --- rejecting.", i);
+                    psErrorStackPrint(stderr, "Unable to measure mean variance for image %d", i);
+                    options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_PSF;
+                    goto DONE;
+                } else {
+                    // Desperate retry
+                    mean = bg->sampleMean;
+                }
+            } else {
+                // Retry with all available pixels
+                mean = bg->robustMedian;
+            }
+        } else {
+            // First attempt
+            mean = bg->robustMedian;
         }
 
@@ -177,4 +200,6 @@
         }
 
+    DONE:
+        psFree(bg);
         if (!ppStackFilesIterateUp(config)) {
             psFree(rng);
