Index: trunk/psLib/src/imageops/psImageMap.c
===================================================================
--- trunk/psLib/src/imageops/psImageMap.c	(revision 21183)
+++ trunk/psLib/src/imageops/psImageMap.c	(revision 23989)
@@ -211,18 +211,30 @@
             // XXX need to supply a mask and skip the masked pixels when calculating the centroid
             // this will not in general be properly weighted...
-            if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
+            if (!psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
+		psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
+		return false;
+	    }
+
+	    // XXX ensure only one option is selected, or save both position and width
+	    map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
+
+	    if (isnan(map->map->data.F32[iy][ix])) {
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
+	    } else {
                 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 0;
-                // XXX ensure only one option is selected, or save both position and width
-                map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
 
                 // calculate the mean position and save:
                 psStatsInit (meanStat);
-                psVectorStats (meanStat, xCell, NULL, NULL, 0);
+                if (!psVectorStats (meanStat, xCell, NULL, NULL, 0)) {
+		    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
+		    return false;
+		}
                 xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
                 psStatsInit (meanStat);
-                psVectorStats (meanStat, yCell, NULL, NULL, 0);
+                if (!psVectorStats (meanStat, yCell, NULL, NULL, 0)) {
+		    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
+		    return false;
+		}
                 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
-            } else {
-                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
             }
 
