Index: trunk/psphot/src/psphotImageMedian.c
===================================================================
--- trunk/psphot/src/psphotImageMedian.c	(revision 6441)
+++ trunk/psphot/src/psphotImageMedian.c	(revision 6481)
@@ -8,4 +8,17 @@
 // use no more than MAX_SAMPLE_PIXELS pixels for each median box
 static int MAX_SAMPLE_PIXELS;
+
+static char *backImage = NULL;
+static char *backModel = NULL;
+
+bool psphotBackgroundNames (psMetadata *arguments) {
+
+    bool status;
+
+    backImage = psMetadataLookupStr (&status, arguments, "BACKGROUND_IMAGE");
+    backModel = psMetadataLookupStr (&status, arguments, "BACKGROUND_MODEL");
+
+    return true;
+}
 
 // generate the median in NxN boxes, clipping heavily
@@ -211,4 +224,9 @@
 	}
     }
+
+    // optionally save background
+    if (backImage != NULL) psphotSaveImage (NULL, background, backImage);
+    if (backModel != NULL) psphotSaveImage (NULL, model, backModel);
+
     psLogMsg ("psphot", 3, "subtracted background model: %f sec\n", psTimerMark ("psphot"));
     psFree (rnd);
