Index: trunk/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 14455)
+++ trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 14480)
@@ -33,7 +33,13 @@
     stamp->x = 0;
     stamp->y = 0;
+    stamp->xNorm = 0.0;
+    stamp->yNorm = 0.0;
     stamp->matrix = NULL;
     stamp->vector = NULL;
     stamp->status = status;
+
+    stamp->reference = NULL;
+    stamp->input = NULL;
+    stamp->weight = NULL;
 
     return stamp;
@@ -137,4 +143,13 @@
                 stamp->x = xBest;
                 stamp->y = yBest;
+                stamp->xNorm = 2.0 * (float)(xBest - numCols/2.0) / (float)numCols;
+                stamp->yNorm = 2.0 * (float)(yBest - numRows/2.0) / (float)numRows;
+
+                // Reset the postage stamps since we're making a new stamp
+                psFree(stamp->reference);
+                psFree(stamp->input);
+                psFree(stamp->weight);
+                stamp->reference = stamp->input = stamp->weight = NULL;
+
                 if (fluxBest > threshold) {
                     stamp->status = PM_SUBTRACTION_STAMP_CALCULATE;
@@ -154,2 +169,61 @@
     return stamps;
 }
+
+
+bool pmSubtractionExtractStamps(psArray *stamps, psImage *reference, psImage *input, psImage *weight,
+                                int footprint, const pmSubtractionKernels *kernels)
+{
+    PS_ASSERT_ARRAY_NON_NULL(stamps, false);
+    PS_ASSERT_IMAGE_NON_NULL(reference, false);
+    PS_ASSERT_IMAGE_TYPE(reference, PS_TYPE_F32, false);
+    if (input) {
+        PS_ASSERT_IMAGE_NON_NULL(input, false);
+        PS_ASSERT_IMAGES_SIZE_EQUAL(input, reference, false);
+        PS_ASSERT_IMAGE_TYPE(input, PS_TYPE_F32, false);
+    }
+    if (weight) {
+        PS_ASSERT_IMAGE_NON_NULL(weight, false);
+        PS_ASSERT_IMAGES_SIZE_EQUAL(weight, reference, false);
+        PS_ASSERT_IMAGE_TYPE(weight, PS_TYPE_F32, false);
+    }
+
+    int numCols = reference->numCols, numRows = reference->numRows; // Size of images
+    int size = kernels->size + footprint; // Size of postage stamps
+
+    if (!weight) {
+        // Use the input as a rough approximation to the variance map, and HOPE that it's positive.
+        weight = input;
+    }
+
+    for (int i = 0; i < stamps->n; i++) {
+        pmSubtractionStamp *stamp = stamps->data[i]; // Stamp of interest
+
+
+        int x = stamp->x, y = stamp->y; // Stamp coordinates
+        if (x < size || x > numCols - size || y < size || y > numRows - size) {
+            psError(PS_ERR_UNKNOWN, false, "Stamp %d (%d,%d) is within the image border.\n", i, x, y);
+            return false;
+        }
+
+        psRegion region = psRegionSet(x - size, x + size + 1, y - size, y + size + 1); // Region of interest
+
+        psImage *refSub = psImageSubset(reference, region); // Subimage with stamp
+        stamp->reference = psKernelAllocFromImage(refSub, size, size);
+        psFree(refSub);                 // Drop reference
+
+        if (input) {
+            psImage *inSub = psImageSubset(input, region); // Subimage with stamp
+            stamp->input = psKernelAllocFromImage(inSub, size, size);
+            psFree(inSub);              // Drop reference
+        }
+
+        psImage *wtSub = psImageSubset(weight, region); // Subimage with stamp
+        stamp->weight = psKernelAllocFromImage(wtSub, size, size);
+        psFree(wtSub);                 // Drop reference
+
+    }
+
+    return true;
+}
+
+
