// Make RGBs Macro by Christophe Leterrier // 14/09/2023 // //This takes a folder full of multi-channel tif images. // • Generates grayscale or LUT-coded single-channel RGB images. // • Generates several RGB overlays using specified channels and the LUTs used for these channels in the multi-channel image. // Each overlay is encoded by a string in the options dialog: "012,123" means an overlay of channels 0, 1 and 2, and an overlay of channels 1, 2 and 3 // If empty, an overlay of all channels is generated // • Generates an RGB overlay with annotation (zoom boxes, scale bar) burned in // // Folder Structure: // // •Experiment folder // |–•Input folder // |-•Output folder "RGB" (created from the input folder by this macro) macro "Generate_RGBs" { //*************** Initialization *************** // Defulat parameters for the batch macro MACRO_NAME = "Generate RGBs"; 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 = "RGB"; // Suffix to add to the output folder // Default values for the Options Panel FILE_IN_DEF = ""; FILE_OUT_DEF = ""; IND_DEF = true; LUTS_DEF = false; CONVRGB_DEF = true; SAVE_OV_DEF = true; CHAN_DEF = "012,123"; // Each overlay is coded by the channels that are present SAVE_ANNO_DEF = true; // Get the input folder name INPUT_DIR=getDirectory("Select the input stacks 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.addString("Include file names containing", FILE_IN_DEF, 15); Dialog.addString("Exclude file names containing", FILE_OUT_DEF, 15); Dialog.addCheckbox("Save individual channels", IND_DEF); Dialog.addCheckbox("Use colored LUTs", LUTS_DEF); Dialog.addCheckbox("Convert channels to RGB", CONVRGB_DEF); Dialog.addCheckbox("Save overlay", SAVE_OV_DEF); Dialog.addString("Overlay channels #", CHAN_DEF, 15); Dialog.addCheckbox("Save annotated overlay", SAVE_ANNO_DEF); Dialog.show(); // Feeding variables from dialog choices FILE_IN = Dialog.getString(); FILE_OUT = Dialog.getString(); if (FILE_OUT == "") FILE_OUT = ":"; // using a forbidden character in file names as exclusion string to exclude nothing SAVE_IND = Dialog.getCheckbox(); LUTS = Dialog.getCheckbox(); CONVRGB = Dialog.getCheckbox(); SAVE_OV = Dialog.getCheckbox(); CHAN = Dialog.getString(); CHAN_EL = split(CHAN, ","); // split the CHAN aray into different overlay patterns SAVE_ANNO = Dialog.getCheckbox(); // 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-1 && indexOf(ALL_NAMES[n], FILE_OUT)==-1) { // Get the file path FILE_PATH=INPUT_DIR+ALL_NAMES[n]; // Store components of the file name FILE_NAME=File.getName(FILE_PATH); FILE_DIR = File.getParent(FILE_PATH); FILE_SEP = getFileExtension(FILE_NAME); FILE_SHORTNAME = FILE_SEP[0]; FILE_EXT = FILE_SEP[1]; print(""); print("INPUT_PATH:", FILE_PATH); // print("FILE_NAME:", FILE_NAME); // print("FILE_DIR:", FILE_DIR); // print("FILE_EXT:", FILE_EXT); // print("FILE_SHORTNAME:", FILE_SHORTNAME); // Open input file open(FILE_PATH); IN_ID = getImageID(); IN_TITLE = getTitle(); getDimensions(w, h, ch, sl, fr); // Processing // default overlay all channels if no CHAN string if (CHAN == "") { for (c=0; c 2) { for (k = 1; k < nameparts.length - 1; k++) { shortname += "." + nameparts[k]; } } extname = "." + nameparts[nameparts.length - 1]; namearray = newArray(shortname, extname); return namearray; } // function to transform an list of channels overlay string ("013") into a binary encoded overlay string ("1101") function makeOvString(channels, nchan) { ovstring = ""; for (k=0; k -1) ovstring = ovstring + "1"; else ovstring = ovstring + "0"; } return ovstring; }