Index: trunk/psastro/src/psastroRemoveClumps.c
===================================================================
--- trunk/psastro/src/psastroRemoveClumps.c	(revision 17109)
+++ trunk/psastro/src/psastroRemoveClumps.c	(revision 20805)
@@ -11,11 +11,11 @@
     float Ymax = obj->FP->y;
     for (int i = 0; i < input->n; i++) {
-	obj = (pmAstromObj *)input->data[i];
-	if (!isfinite(obj->FP->x)) continue;
-	if (!isfinite(obj->FP->y)) continue;
-	Xmin = PS_MIN (Xmin, obj->FP->x);
-	Xmax = PS_MAX (Xmax, obj->FP->x);
-	Ymin = PS_MIN (Ymin, obj->FP->y);
-	Ymax = PS_MAX (Ymax, obj->FP->y);
+        obj = (pmAstromObj *)input->data[i];
+        if (!isfinite(obj->FP->x)) continue;
+        if (!isfinite(obj->FP->y)) continue;
+        Xmin = PS_MIN (Xmin, obj->FP->x);
+        Xmax = PS_MAX (Xmax, obj->FP->x);
+        Ymin = PS_MIN (Ymin, obj->FP->y);
+        Ymax = PS_MAX (Ymax, obj->FP->y);
     }
 
@@ -27,10 +27,10 @@
     // accumulate 2D histogram in image
     for (int i = 0; i < input->n; i++) {
-	obj = (pmAstromObj *)input->data[i];
-	if (!isfinite(obj->FP->x)) continue;
-	if (!isfinite(obj->FP->y)) continue;
-	int Xi = PS_MIN (PS_MAX((obj->FP->x - Xmin) / scale + 5, 0), count->numCols);
-	int Yi = PS_MIN (PS_MAX((obj->FP->y - Ymin) / scale + 5, 0), count->numRows);
-	count->data.U32[Yi][Xi] ++;
+        obj = (pmAstromObj *)input->data[i];
+        if (!isfinite(obj->FP->x)) continue;
+        if (!isfinite(obj->FP->y)) continue;
+        int Xi = PS_MIN (PS_MAX((obj->FP->x - Xmin) / scale + 5, 0), count->numCols);
+        int Yi = PS_MIN (PS_MAX((obj->FP->y - Ymin) / scale + 5, 0), count->numRows);
+        count->data.U32[Yi][Xi] ++;
     }
 
@@ -38,15 +38,15 @@
     psStats *stats = psStatsAlloc (PS_STAT_MAX | PS_STAT_MAX | PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     if (!psImageStats(stats, count, NULL, 0)) {
-	psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
-	psFree(stats);
-	psFree(count);
-	return NULL;
+        psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
+        psFree(stats);
+        psFree(count);
+        return NULL;
     }
 
     if (stats->max < 1) {
-	psError(PS_ERR_UNKNOWN, false, "no valid sources in image\n");
-	psFree(stats);
-	psFree(count);
-	return NULL;
+        psError(PS_ERR_UNKNOWN, false, "no valid sources in image\n");
+        psFree(stats);
+        psFree(count);
+        return NULL;
     }
 
@@ -55,14 +55,16 @@
     psTrace ("psastro", 4, "skipping stars in cells with more than %f stars\n", limit);
 
+    psastroVisualPlotRemoveClumps (input, count, scale, limit);
+
     // find and exclude objects in bad pixels
     psArray *output = psArrayAllocEmpty (input->n);
     for (int i = 0; i < input->n; i++) {
-	obj = (pmAstromObj *)input->data[i];
-	if (!isfinite(obj->FP->x)) continue;
-	if (!isfinite(obj->FP->y)) continue;
-	int Xi = PS_MIN (PS_MAX((obj->FP->x - Xmin) / scale + 5, 0), count->numCols);
-	int Yi = PS_MIN (PS_MAX((obj->FP->y - Ymin) / scale + 5, 0), count->numRows);
-	if (count->data.U32[Yi][Xi] > limit) continue;
-	psArrayAdd (output, 16, obj);
+        obj = (pmAstromObj *)input->data[i];
+        if (!isfinite(obj->FP->x)) continue;
+        if (!isfinite(obj->FP->y)) continue;
+        int Xi = PS_MIN (PS_MAX((obj->FP->x - Xmin) / scale + 5, 0), count->numCols);
+        int Yi = PS_MIN (PS_MAX((obj->FP->y - Ymin) / scale + 5, 0), count->numRows);
+        if (count->data.U32[Yi][Xi] > limit) continue;
+        psArrayAdd (output, 16, obj);
     }
 
@@ -77,11 +79,11 @@
 for (int iy = 0; iy < count->numRows; iy++) {
     for (int ix = 0; ix < count->numCols; ix++) {
-	if (count->data.U32[iy][ix] > limit) {
-	    psPlane *pixel = psPlaneAlloc();
-	    pixel->x = ix;
-	    pixel->y = iy;
-	    psArrayAdd (badpix, 16, pixel);
-	    psFree (pixel);
-	}
+        if (count->data.U32[iy][ix] > limit) {
+            psPlane *pixel = psPlaneAlloc();
+            pixel->x = ix;
+            pixel->y = iy;
+            psArrayAdd (badpix, 16, pixel);
+            psFree (pixel);
+        }
     }
 }
