// Manual alignment of two fluorescent images // 14.06.16 15:21 // N. Vischer /* We use the first two images that were loaded (see "Window" menu); - run macro "Align Contours": - in both images, contours are derived by temporary smoothing and thresholding - in Image#1, contour#1 is shown as red Overlay, and contour#2 as green selection - user is asked to drag green contour to correct position (use zoom >=1 for precision) - after clicking "OK", image#2 is translated accordingly. Remarks: - precision is 1 pixel (~70 nm?) as we don't temporarily enlarge the images - borders caused by shifting contain contents of unshifted image (i.e. 'translate' was not used to avoid black margins) */ macro "Align Contours [F2]"{ selectImage(1); run("Select None"); run("Remove Overlay"); snapshot; run("Gaussian Blur...", "sigma=3"); setAutoThreshold("Otsu dark"); run("Create Selection"); reset; resetThreshold; run("Properties... ", " stroke=red"); run("Add Selection..."); selectImage(2); run("Remove Overlay"); run("Select None"); snapshot; run("Gaussian Blur...", "sigma=3"); setAutoThreshold("Otsu dark"); run("Create Selection"); reset; resetThreshold; selectImage(1); run("Restore Selection"); run("Properties... ", " stroke=green"); getSelectionBounds(x1, y1, width, height); waitForUser("Drag green outline to correct position, then click OK"); if(selectionType !=4 && selectionType !=9) exit("Unexpected selection type"); getSelectionBounds(x2, y2, width, height); dx = x1 - x2; dy = y1 - y2; selectImage(2); run("Select All"); run("Copy"); setSelectionLocation(-dx, -dy); run("Paste"); run("Select None"); selectImage(1); run("Select None"); run("Remove Overlay"); }