//This macro uses the Image Stabilizer and Image Stabilizer Log Applier plugins //by Kang Li to register *.tif image stacks generated by the Micron imaging systems //from Phoenix Research Laboratories. These instruments are used to image the fundus //(posterior eye) of live mice and rats, and can acquire and/or export multiframe //data in the form of *.tif image stacks. Image quality may be improved by averaging //the image stacks, but only if image shifts due to ocular movement are corrected. // //The macro corrects for image shifts. Two rounds of registration (translation and //affine) are applied to a duplicate of the stack that is centered on the image and //cropped to avoid the dark background that surrounds the image, which can bias //registration. The transformation coefficients generated in each round are applied //to the full-sized image stack, which is then averaged, sharpened with two rounds of //unsharp mask, and cropped. // //The macro handles images of different pixel dimensions, as in those output by the //Micron III (1024x768 pixels) and Micron IV (800x800 pixels). Other sizes can also //be accomodated. For registration, it is assumed that the circular fundus image //lies in the center of and fills the height of the original image. The final image is //cropped to yield a square image with dimensions of the original image height, and a //circular selection is displayed for further processing. //Use of the macro to process Micron images is described in the following publication, //which may be cited if desired: // //M.P. Krebs, M. Xiao, K. Sheppard, W. Hicks, P.M. Nishina. 2016. Bright-Field Imaging //and Optical Coherence Tomography of the Mouse Posterior Eye. Methods in Molecular //Biology. 1438:395-416. DOI:10.1007/978-1-4939-3661-8_20 path = getDirectory("Choose an Input Directory"); filename = getFileList(path); path2 = getDirectory("Choose an Output Directory"); for (i=0; i1) { //Process only files with more than one slice //Create a cropped duplicate of the image stack to avoid alignment bias due to the dark //background around the image run("Specify...", "width="+cropWH+" height="+cropWH+" x="+cropX+" y="+cropY+" slice=1 centered"); run("Duplicate...", "title=[Cropped] duplicate range=1-"+s); //Register the cropped stack with a Translation transformation and apply the //coefficients to the original image run("Image Stabilizer", "transformation=Translation maximum_pyramid_levels=1 template_update_coefficient=0.90 maximum_iterations=200 error_tolerance=0.0000001 log_transformation_coefficients"); selectWindow(filename[i]); run("Image Stabilizer Log Applier", " "); selectWindow("Cropped.log"); run("Close"); selectWindow("Cropped"); //Register the Translation-registered cropped stack with an Affine transformation and //apply the coefficients to the Translation-transformed image run("Image Stabilizer", "transformation=Affine maximum_pyramid_levels=1 template_update_coefficient=0.90 maximum_iterations=200 error_tolerance=0.0000001 log_transformation_coefficients"); selectWindow(filename[i]); run("Image Stabilizer Log Applier", " "); selectWindow("Cropped.log"); run("Close"); //Average the registered stack, apply unsharp mask twice and crop the result with a //circular mask run("Z Project...", "start=1 stop="+s+" projection=[Average Intensity]"); run("Unsharp Mask...", "radius=3 mask=0.70"); run("Unsharp Mask...", "radius=3 mask=0.50"); run("Specify...", "width="+h+" height="+h+" x="+cropX+" y="+cropY+" oval centered"); run("Crop"); saveAs("tiff", path2 + filename[i]); run("Close All"); } else {run("Close"); } } }