// Batch process macro template by Christophe Leterrier // 14/09/2023 // //This takes an input folder, process each file that has a certain extension, an saves the resulting files in an output folder next to the input folder. // // Folder Structure: // // •Experiment folder // |–•Input folder // |-•Output folder (created from the input folder by this macro) macro "Batch_Macro" { //*************** Initialization *************** // Defulat parameters for the batch macro MACRO_NAME = "Batch Macro"; EXT = ".tif"; // extension to identify the files to process inside the input folder BATCH = true; // use the batch mode when looping on images SHORTEN_FOLDER = false; // shorten the input folder name to generate the output folder name, leaving only the first "word" FOLDER_SUFFIX = "processed"; // Suffix to add to the output folder // Default values for the Options Panel LUTS_DEF = false; CHAN_DEF = "0,1,2,3"; // Get the input folder name INPUT_DIR=getDirectory("Select the input images directory"); print("\n\n\n*** " + MACRO_NAME + " Log ***"); print(""); print("INPUT_DIR :" + INPUT_DIR); //*************** Dialog *************** // Creation of the dialog box Dialog.create(MACRO_NAME + " Options"); Dialog.addCheckbox("Use colored LUTs", LUTs_DEF); Dialog.addString("Overlay channels #", CHAN_DEF, 15); Dialog.show(); // Feeding variables from dialog choices LUTS = Dialog.getCheckbox(); CHAN = Dialog.getString(); // Get all file names ALL_NAMES=getFileList(INPUT_DIR); Array.sort(ALL_NAMES); N_LENGTH = ALL_NAMES.length; ALL_EXT=newArray(N_LENGTH); // Create extensions array for (i = 0; i < N_LENGTH; i++) { // print(ALL_NAMES[i]); ALL_NAMES_PARTS = getFileExtension(ALL_NAMES[i]); ALL_EXT[i] = ALL_NAMES_PARTS[1]; } //*************** Prepare processing *************** if (BATCH == true) setBatchMode(true); // Create the output folder (by default it is a folder next to the input folder) OUTPUT_DIR = File.getParent(INPUT_DIR); OUTPUT_NAME = File.getName(INPUT_DIR); // Shorten input folder name (optional) if ( SHORTEN_FOLDER == true) { OUTPUT_SHORTA = split(OUTPUT_NAME, " "); OUTPUT_SHORT = OUTPUT_SHORTA[0]; } else OUTPUT_SHORT = OUTPUT_NAME; OUTPUT_DIR = OUTPUT_DIR + File.separator + OUTPUT_SHORT + " " + FOLDER_SUFFIX + File.separator; if (File.isDirectory(OUTPUT_DIR) == false) { File.makeDirectory(OUTPUT_DIR); } OUTPUT_PARENT_DIR=File.getParent(OUTPUT_DIR); print("OUTPUT_DIR: " + OUTPUT_DIR); print("OUTPUT_PARENT_DIR: " + OUTPUT_PARENT_DIR); //*************** Processing *************** // Loop on all chosen extensions for (n=0; n 2) { for (k = 1; k < nameparts.length - 1; k++) { shortname += "." + nameparts[k]; } } extname = "." + nameparts[nameparts.length - 1]; namearray = newArray(shortname, extname); return namearray; }