Index: /branches/eam_branches/ipp-20220316/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- /branches/eam_branches/ipp-20220316/ppImage/src/ppImageDetrendReadout.c	(revision 42157)
+++ /branches/eam_branches/ipp-20220316/ppImage/src/ppImageDetrendReadout.c	(revision 42158)
@@ -63,4 +63,14 @@
     // psLogMsg ("ppImage", 6, "check video: %f sec\n", psTimerMark ("detrend.readout"));
 
+    // XXX for GPC2, there are some bizzare cell levels that need to be filtered out
+    // Here I measure the median background before overscan subtraction, but an alternative
+    // is to use the overscan-subtracted image.
+    // XX if (0) {
+    // XX 	psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN);
+    // XX 	psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
+    // XX 	psImageBackground (stats, NULL, input->image, NULL, 0xffff, rng);
+    // XX 	readoutBackground = stats->robustMedian;
+    // XX }
+
     // Masking on the basis of pixel value needs to be done before anything else, so the values are pristine.
     if (options->doMaskBuild) {
@@ -113,4 +123,17 @@
       }
       // psLogMsg ("ppImage", 6, "subtract overscan: %f sec\n", psTimerMark ("detrend.readout"));
+    }
+
+    // measure the overscan-subtracted readoutBackground here (or subtract the overscan value?)
+    if (1) {
+	psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN);
+	psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
+	psImageBackground (stats, NULL, input->image, NULL, 0xffff, rng);
+
+	// save this value somewhere
+	pmHDU *hdu = pmHDUFromReadout(input);  // HDU of interest
+	psMetadataAddF32(hdu->header, PS_LIST_TAIL, "BACK_VAL", PS_META_REPLACE, "Median cell background", stats->robustMedian);
+	psFree (stats);
+	psFree (rng);
     }
 
