Index: trunk/ppImage/src/Makefile.am
===================================================================
--- trunk/ppImage/src/Makefile.am	(revision 15928)
+++ trunk/ppImage/src/Makefile.am	(revision 15933)
@@ -27,4 +27,5 @@
 	ppImagePixelStats.c \
 	ppImageMetadataStats.c \
+	ppImageReplaceBackground.c \
 	ppImageDefineFile.c \
 	ppImageFileCheck.c \
@@ -54,4 +55,5 @@
 	ppImagePixelStats.c \
 	ppImageMetadataStats.c \
+	ppImageReplaceBackground.c \
 	ppImageDefineFile.c \
 	ppImageFileCheck.c \
Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 15928)
+++ trunk/ppImage/src/ppImage.h	(revision 15933)
@@ -36,4 +36,5 @@
     bool doAstromMosaic;                // full-mosaic Astrometry
     bool doStats;			// call ppStats on the image
+    bool replaceMasked;			// fill in masked values with background model
 
     // output files requested
@@ -127,4 +128,6 @@
 bool ppImageAddstar (pmConfig *config);
 
+bool ppImageReplaceBackground (pmConfig *config, pmFPAview *view, ppImageOptions *options);
+
 bool ppImageMosaicChip (pmConfig *config, const ppImageOptions *options, const pmFPAview *view,
                         const char *outFile, const char *inFile);
Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 15928)
+++ trunk/ppImage/src/ppImageLoop.c	(revision 15933)
@@ -90,4 +90,10 @@
         }
 
+	// replace the masked pixels with the background level
+	if (options->replaceMasked) {
+	    if (!ppImageReplaceBackground (config, view, options)) 
+		ESCAPE ("Unable to replace masked pixels with background level");
+	}
+
         // Close cells (XXX shouldn't pmFPAfileClose iterate down as needed?)
         view->cell = -1;
Index: trunk/ppImage/src/ppImageOptions.c
===================================================================
--- trunk/ppImage/src/ppImageOptions.c	(revision 15928)
+++ trunk/ppImage/src/ppImageOptions.c	(revision 15933)
@@ -272,4 +272,6 @@
     options->fringeKeep = psMetadataLookupF32(NULL, recipe, "FRINGE.KEEP");
 
+    options->replaceMasked  = psMetadataLookupBool(NULL, recipe, "REPLACE.MASKED");
+
     return options;
 }
