Index: trunk/ppStack/src/ppStackSources.c
===================================================================
--- trunk/ppStack/src/ppStackSources.c	(revision 27276)
+++ trunk/ppStack/src/ppStackSources.c	(revision 27277)
@@ -275,5 +275,5 @@
             options->norm = psVectorAlloc(num, PS_TYPE_F32);
             for (int i = 0; i < num; i++) {
-                if (!isfinite(trans->data.F32[i])) {
+                if (inputMask->data.U8[i] || !isfinite(trans->data.F32[i])) {
                     continue;
                 }
@@ -315,5 +315,5 @@
         // Double check: all transparencies should be zero
         {
-            psArray *matches = pmSourceMatchSources(sourceLists, radius); // List of matches
+            psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches
             if (!matches) {
                 psError(PPSTACK_ERR_DATA, false, "Unable to match sources");
@@ -321,16 +321,18 @@
                 return false;
             }
-            psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej,
-                                                   transThresh, starRej, starSys);
+            psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1,
+                                                   iter2, starRej2, starSys2, starLimit,
+                                                   transIter, transRej, transThresh); // Transparencies
             for (int i = 0; i < num; i++) {
                 fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]);
             }
             psFree(trans);
-        }
-#endif
-    }
-
-
-#if 0
+            psFree(matches);
+        }
+#endif
+    }
+
+
+#if 1
     // Position offsets
     {
@@ -342,10 +344,54 @@
         }
         for (int i = 0; i < num; i++) {
-            psVector *offset = offsets->data[i];
-            fprintf(stderr, "Offset %d: %f,%f\n", i, offset->data.F32[0], offset->data.F32[1]);
+            if (options->inputMask->data.U8[i]) {
+                continue;
+            }
+            psArray *sources = sourceLists->data[i]; // Sources of interest
+            psVector *offset = offsets->data[i];                      // Offsets for image
+            float dx = offset->data.F32[0], dy = offset->data.F32[1]; // Offsets to apply
+            if (!isfinite(dx) || !isfinite(dy)) {
+                continue;
+            }
+            psLogMsg("ppStack", PS_LOG_INFO, "Applying astrometric correction to image %d: %f,%f\n",
+                     i, dx, dy);
+            for (int j = 0; j < sources->n; j++) {
+                pmSource *source = sources->data[j]; // Source of interest
+                if (!source) {
+                    continue;
+                }
+                if (source->modelPSF) {
+                    source->modelPSF->params->data.F32[PM_PAR_XPOS] -= dx;
+                    source->modelPSF->params->data.F32[PM_PAR_YPOS] -= dy;
+                }
+                if (source->peak) {
+                    source->peak->xf -= dx;
+                    source->peak->yf -= dy;
+                }
+            }
         }
         psFree(offsets);
     }
 #endif
+
+#ifdef TESTING
+        // Double check: all offsets should be zero
+        {
+            psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches
+            if (!matches) {
+                psError(PPSTACK_ERR_DATA, false, "Unable to match sources");
+                psFree(zp);
+                return false;
+            }
+            psArray *offsets = pmSourceMatchRelastro(matches, num, tol, iter1, starRej1,
+                                                     iter2, starRej2, starLimit); // Shifts for each image
+            for (int i = 0; i < num; i++) {
+                psVector *offset = offsets->data[i]; // Offsets for image
+                fprintf(stderr, "Offset of image %d: %f,%f\n", i, offset->data.F32[0], offset->data.F32[1]);
+            }
+            psFree(offsets);
+            psFree(matches);
+        }
+#endif
+
 
     if (options->photometry) {
