Index: /trunk/ppMerge/src/ppMergeMask.h
===================================================================
--- /trunk/ppMerge/src/ppMergeMask.h	(revision 15952)
+++ /trunk/ppMerge/src/ppMergeMask.h	(revision 15953)
@@ -37,5 +37,5 @@
     );
 
-bool ppMergeMaskGrowReadout (pmReadout *readout, psMaskType maskVal);
+bool ppMergeMaskGrowReadout (pmReadout *readout, psMaskType maskVal, int nPixels);
 
 bool ppMergeMaskReadoutStats(const pmReadout *readout, 
Index: /trunk/ppMerge/src/ppMergeMaskGrow.c
===================================================================
--- /trunk/ppMerge/src/ppMergeMaskGrow.c	(revision 15952)
+++ /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;
Index: /trunk/ppMerge/src/ppMergeOptions.c
===================================================================
--- /trunk/ppMerge/src/ppMergeOptions.c	(revision 15952)
+++ /trunk/ppMerge/src/ppMergeOptions.c	(revision 15953)
@@ -64,4 +64,5 @@
     options->satMask = 0x00;
     options->badMask = 0x00;
+    options->growPixels = 0;
     return options;
 }
@@ -156,4 +157,5 @@
     OPTION_PARSE(options->maskBad,           recipe, "MASK.BAD",       F32);
     OPTION_PARSE(options->statsByChip,       recipe, "STATS.BY.CHIP",  Bool);
+    OPTION_PARSE(options->growPixels,        recipe, "MASK.GROW.NPIX", S32);
 
     const char *masks = psMetadataLookupStr(NULL, recipe, "MASKVAL");
Index: /trunk/ppMerge/src/ppMergeOptions.h
===================================================================
--- /trunk/ppMerge/src/ppMergeOptions.h	(revision 15952)
+++ /trunk/ppMerge/src/ppMergeOptions.h	(revision 15953)
@@ -43,4 +43,5 @@
     psMaskType satMask;                 // Mask value for saturated pixels
     psMaskType badMask;                 // Mask value for bad (low) pixels
+    int growPixels;
 } ppMergeOptions;
 
