macro "Batch_Zooms" { Conc = true; Montage = false; setBatchMode(true); stackID = getImageID(); stackTitle = getTitle(); nROI = roiManager("count"); ConcString = "open"; for (r = 0; r < nROI; r++) { // loop on ROIs in the ROI manager selectImage(stackID); roiManager("select", r); if (Roi.getType == "polygon" || Roi.getType == "freehand") { // case of a rotated rectangle (after rotating a rectange ROI or using the specific tool) inID = getImageID(); inTitle = getTitle(); inLabel = getInfo("slice.label"); getDimensions(w, h, ch, sl, fr); Stack.getPosition(currch, currsl, currfr); run("Duplicate...", " "); // Rename output image from the input image label or title (if no label) if (inLabel == "") outTitle1 = inTitle; else outTitle1 = inLabel; outTitle2 = replace(outTitle1, "-C=.", "_zrot0"); if (outTitle2 == outTitle1)outTitle2 = replace(outTitle1, ".tif", "_zrot0_.tif"); if (outTitle2 == outTitle1) outTitle2 = outTitle1 + "_zrot0"; rename(outTitle2); // Rename each slice if multicolor if (ch > 1) { for (c = 0; c < ch; c++) { Stack.setPosition((c+1), 1, 1); chLabel = getInfo("slice.label"); if (inLabel == "") outLabel1 = inTitle; else outLabel1 = chLabel; outLabel2 = replace(outLabel1, "-C=", "_zrot0-C="); if (outLabel2 == outLabel1)outLabel2 = replace(outLabel1, ".tif", "_zrot0_.tif"); if (outLabel2 == outLabel1) outLabel2 = outLabel1 + "_zrot0"; Property.setSliceLabel(outLabel2); } } } else if (Roi.getType == "rectangle") { // case of a rectangle ROI // Get info in input image and dupolicate the ROI inID = getImageID(); inTitle = getTitle(); inLabel = getInfo("slice.label"); getDimensions(w, h, ch, sl, fr); Stack.getPosition(currch, currsl, currfr); run("Duplicate...", "duplicate slices=" + currsl); // Rename output image from the input image label or title (if no label) if (inLabel == "") outTitle1 = inTitle; else outTitle1 = inLabel; outTitle2 = replace(outTitle1, "-C=.", "_zrot0"); if (outTitle2 == outTitle1)outTitle2 = replace(outTitle1, ".tif", "_zrot0_.tif"); if (outTitle2 == outTitle1) outTitle2 = outTitle1 + "_zrot0"; rename(outTitle2); // Rename each slice if multicolor if (ch > 1) { for (c = 0; c < ch; c++) { Stack.setPosition((c+1), 1, 1); chLabel = getInfo("slice.label"); if (inLabel == "") outLabel1 = inTitle; else outLabel1 = chLabel; outLabel2 = replace(outLabel1, "-C=", "_zrot0-C="); if (outLabel2 == outLabel1)outLabel2 = replace(outLabel1, ".tif", "_zrot0_.tif"); if (outLabel2 == outLabel1) outLabel2 = outLabel1 + "_zrot0"; Property.setSliceLabel(outLabel2); } } } ConcString = ConcString + " image" + (r+1) + "=[" + outTitle2 + "]"; } // Concatenate all zoom images if option is chosen if (Conc == true) { // Close the input stack (to avoid concatenating it with the zooms) selectImage(stackID); run("Select None"); Stack.setPosition(1, 1, 1); // close(); run("Concatenate...", "title=" + stackTitle + "_zooms " + ConcString); if (Montage == true) { run("Make Montage...", "columns=1 rows=" + nROI + " scale=1 border=10"); } } setBatchMode("exit and display");; }