Index: trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendReadout.c	(revision 13461)
+++ trunk/ppImage/src/ppImageDetrendReadout.c	(revision 13498)
@@ -18,6 +18,5 @@
     // Masking on the basis of pixel value needs to be done before anything else, so the values are pristine.
     if (options->doMask || options->doShutter || options->doFlat || options->doPhotom) {
-        // create the target mask and weight images
-        pmReadoutGenerateMaskWeight(input, true);
+        pmReadoutGenerateMask(input, true);
     }
     // apply the externally supplied mask to the input->mask pixels
@@ -50,4 +49,10 @@
             return false;
         }
+    }
+
+    // Weight on the basis of pixel value needs to be done after the overscan has been subtracted
+    if (options->doMask || options->doShutter || options->doFlat || options->doPhotom) {
+        // create the target mask and weight images
+        pmReadoutGenerateWeight(input, true);
     }
 
