Index: trunk/psLib/src/imageops/psImageMap.c
===================================================================
--- trunk/psLib/src/imageops/psImageMap.c	(revision 23989)
+++ trunk/psLib/src/imageops/psImageMap.c	(revision 25753)
@@ -386,2 +386,32 @@
     return result;
 }
+
+bool psImageMapCleanup (psImageMap *map) {
+
+    if ((map->map->numRows == 1) && (map->map->numCols == 1)) return true;
+
+    // find the weighted average of all pixels
+    float Sum = 0.0;
+    float Wt = 0.0;
+    for (int j = 0; j < map->map->numRows; j++) {
+        for (int i = 0; i < map->map->numCols; i++) {
+            if (!isfinite(map->map->data.F32[j][i])) continue;
+            Sum += map->map->data.F32[j][i] * map->error->data.F32[j][i];
+            Wt += map->error->data.F32[j][i];
+        }
+    }
+
+    float Mean = Sum / Wt;
+
+    // do any of the pixels in the map need to be repaired?
+    // XXX for now, we are just replacing bad pixels with the Mean
+    for (int j = 0; j < map->map->numRows; j++) {
+        for (int i = 0; i < map->map->numCols; i++) {
+            if (isfinite(map->map->data.F32[j][i]) &&
+                (map->error->data.F32[j][i] > 0.0)) continue;
+            map->map->data.F32[j][i] = Mean;
+        }
+    }
+    return true;
+}
+
