// Rotates a set of cell microarray images consisting of red and blue channel images. // // Steps for rotating images: // (1) Open the red image or otherwise the image containing the fluorescent marker. // (2) Select the top spot and bottom spot within a single column. // Use the multi-point tool (https://imagej.nih.gov/ij/docs/guide/146-19.html#sec:Multi-point-Tool). // (3) Run the code. Note that if you installed the macro, you can press "r" to run the code. // (4) Input suffixes for the red and blue channels when prompted by the dialogue box to complete rotation of all image files. // // Rotated images are now saved one directory up in a new folder named "rotated_images". //--------------------------------------------------------------------------------------------// macro "rb_array_rotater [r]" { // creates keyboard shortcut "r" run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel global"); // removes the scale setBatchMode(true); s = selectionType(); // checks selection type to make sure two points are simultaneously selected if (s==-1) { exit("There was no selection."); } else if (s!=10) { exit("There was no point selection."); } else { getSelectionCoordinates(xCoords, yCoords); if (lengthOf(xCoords)!=2) { exit("Two point selections were not made. Tip: Use the multi-point tool."); } x1 = xCoords[1]; y1 = yCoords[1]; x2 = xCoords[0]; y2 = yCoords[0]; if (y2 > y1) { // compensates for when the bottom point is picked first x1 = xCoords[0]; y1 = yCoords[0]; x2 = xCoords[1]; y2 = yCoords[1]; } theta = atan((x2-x1)/(y2-y1))*180/PI; run("Rotate... ", "angle=theta grid=1 interpolation=Bilinear"); run("Select None"); } Dialog.create("Identify and rotate RB images:"); Dialog.addString("Red suffix:", "-red"); Dialog.addString("Blue suffix:", "-blue"); Dialog.show(); redSuffix = Dialog.getString(); blueSuffix = Dialog.getString(); rotate_others(); function rotate_others() { dir = getDirectory("image"); parent_dir = File.getParent(dir)+"/"; rot_dir = parent_dir+"rotated_images"; File.makeDirectory(rot_dir); name_red = getTitle; name = replace(name_red, redSuffix+".tif", ""); name_blue = name+blueSuffix+".tif"; open(dir+name_blue); run("Rotate... ", "angle=theta grid=1 interpolation=Bilinear"); saveAs("tiff",rot_dir+"/"+name_blue); run("Close All"); open(dir+name_red); run("Rotate... ", "angle=theta grid=1 interpolation=Bilinear"); saveAs("tiff",rot_dir+"/"+name_red); run("Close All"); Dialog.create("Status"); Dialog.addMessage("Rotation complete.") Dialog.show(); }; setBatchMode(false); // exit batch mode };