Index: trunk/ppMerge/src/ppMergeMaskGrow.c
===================================================================
--- trunk/ppMerge/src/ppMergeMaskGrow.c	(revision 15937)
+++ trunk/ppMerge/src/ppMergeMaskGrow.c	(revision 15953)
@@ -18,6 +18,6 @@
 // Generate a mask
 bool ppMergeMaskGrow(ppMergeData *data,  // Data
-		    ppMergeOptions *options, // Options
-		    pmConfig *config    // Configuration
+		     ppMergeOptions *options, // Options
+		     pmConfig *config    // Configuration
     )
 {
@@ -35,6 +35,7 @@
 	    while ((roOut = pmFPAviewNextReadout(view, fpaOut, 1))) {
 
-		ppMergeMaskGrowReadout(roOut, options->combine->maskVal);
-
+		// do this N iterations (XXX add to options)
+		ppMergeMaskGrowReadout(roOut, options->combine->maskVal, options->growPixels);
+		ppMergeMaskGrowReadout(roOut, options->combine->maskVal, options->growPixels);
 	    }
         }
@@ -46,7 +47,5 @@
 }
 
-# define NGROW 2
-
-bool ppMergeMaskGrowReadout (pmReadout *readout, psMaskType maskVal) {
+bool ppMergeMaskGrowReadout (pmReadout *readout, psMaskType maskVal, int nPixels) {
 
     if (!readout->mask) return true;
@@ -62,22 +61,26 @@
     for (int iy = 0; iy < Ny; iy++) {
 	for (int ix = 0; ix < Nx; ix++) {
-
-	    if (oldMask->data.U8[iy][ix] && maskVal) {
-
-		for (int jy = -NGROW; jy <= +NGROW; jy++) {
-		    int ny = iy + jy;
-		    if (ny < 0) continue;
-		    if (ny >= Ny) continue;
-		    for (int jx = -NGROW; jx <= +NGROW; jx++) {
-			int nx = ix + jx;
-			if (nx < 0) continue;
-			if (nx >= Nx) continue;
-			newMask->data.U8[ny][nx] |= oldMask->data.U8[iy][ix];
+	    int nSum = 0;
+	    for (int jy = -1; jy <= +1; jy++) {
+		int ny = iy + jy;
+		if (ny < 0) continue;
+		if (ny >= Ny) continue;
+		for (int jx = -1; jx <= +1; jx++) {
+		    if (!jx && !jy) continue;
+		    int nx = ix + jx;
+		    if (nx < 0) continue;
+		    if (nx >= Nx) continue;
+		    if (oldMask->data.U8[ny][nx] & maskVal) {
+			nSum ++;
 		    }
 		}
 	    }
+	    if (nSum >= nPixels) {
+		newMask->data.U8[iy][ix] = maskVal;
+	    } else {
+		newMask->data.U8[iy][ix] = oldMask->data.U8[iy][ix];
+	    }
 	}
     }
-
     psFree (readout->mask);
     readout->mask = newMask;
