// Generates_Tracings_Folder macro by Christophe Leterrier // 13-11-2012 // // Takes a stack (generated by the "Generates_Stacks_Folder" macro) and exports each slice as an 8-bit image in a separate folder (for NeuronJ quantification). // // Folder Structure: // // •Experiment folder // |–•Extracted (created from raw images by the "Extract_ZVI" macro) // |-•Stacks (Created from "Extracted" by the "Generates_Stacks_Folder" macro) // |–•Tracings C=X (created from a stack in "Generates Stacks" by this macro) // new multi-channel version : // just choose the folder containing stacks, detects the number of C=X stacks and asks for which ones to batch export as 8-bit images macro "Generate_Tracings_Folder" { GAUSS_DEF = 0; SAT_DEF = 0; // Get the input stack INPUT_DIR = getDirectory("Select a directory containing the stacks to be traced"); print("\n\n\n*** Generates_Tracings_Folder Log ***"); print("INPUT_DIR:" + INPUT_DIR); // Get the list of stacks named C=X.tif in the input folder ALL_NAMES = getFileList(INPUT_DIR); Array.sort(ALL_NAMES); nSTACKS = 0; for (i = 0; i < ALL_NAMES.length; i++) { if (matches(ALL_NAMES[i], ".*C=\\d.*.tif")) { nSTACKS++; print("Stack " + ALL_NAMES[i]); } } CHANNEL_STACKS = newArray(nSTACKS); for (i = 0; i < ALL_NAMES.length; i++) { if (matches(ALL_NAMES[i], ".*C=\\d.*.tif")) CHANNEL_STACKS[i] = ALL_NAMES[i]; } //Create the dialog for selecting stacks CHANNEL_CHOICE = newArray(CHANNEL_STACKS.length); Dialog.create("Choose Stacks"); Dialog.addMessage("Choose the stacks to extract into the tracings folder:"); for (i = 0; i < CHANNEL_STACKS.length; i++) { Dialog.addCheckbox(CHANNEL_STACKS[i], false); } Dialog.addMessage("Preprocessing steps:"); Dialog.addNumber("Gaussian blur (0 for none)", GAUSS_DEF, 0, 2, "pixels"); Dialog.addNumber("Enhance contrast (0 for none)", SAT_DEF, 3, 5, "% saturated"); Dialog.show(); for (i = 0; i < CHANNEL_STACKS.length; i++) { CHANNEL_CHOICE[i] = Dialog.getCheckbox(); } GAUSS = Dialog.getNumber(); SAT = Dialog.getNumber(); // Gets the parent of parent folder PARENT_DIR = File.getParent(INPUT_DIR); OUTPUT_NAME = "Tracings"; for (i = 0; i < CHANNEL_CHOICE.length; i++) { if (CHANNEL_CHOICE[i] == true) OUTPUT_NAME += " "+ substring(CHANNEL_STACKS[i], 0, lengthOf(CHANNEL_STACKS[i])-4); } // Generates the output path OUTPUT_DIR = PARENT_DIR + File.separator + OUTPUT_NAME + File.separator; File.makeDirectory(OUTPUT_DIR); print("OUTPUT_DIR:" + OUTPUT_DIR); setBatchMode(true); // Opens the stacks and extract them as an 8-bit image sequence in the output folder for (i = 0; i < CHANNEL_STACKS.length; i++) { if (CHANNEL_CHOICE[i] == true) { open(INPUT_DIR + CHANNEL_STACKS[i]); if (GAUSS > 0) { run("Enhance Contrast...", "saturated=" + SAT + " normalize process_all"); } if (SAT > 0) { run("Gaussian Blur...", "sigma=" + GAUSS + " stack"); } resetMinAndMax(); run("8-bit"); run("Image Sequence... ", "format=TIFF name=C=0 start=0 digits=4 use save=[" + OUTPUT_DIR +"]"); close(); } } setBatchMode("exit and display"); print("*** Generates_Tracings_Folder end ***"); showStatus("Generates Tracings Folder finished"); // exec("open", OUTPUT_DIR); }