// Upscale Images macro by Christophe Leterrier // v1 28/05/2022 macro "Upscale_Images" { //*************** Initialization *************** // Macro Name MAC_NAME = "Upscale Images"; // Upscale factor UPS = 2; // String to exclude and include in file names for processing INC = ""; EXC = "Large"; // Get the folder name INPUT_DIR=getDirectory("Select the input stacks directory"); print("\n\n\n*** " + MAC_NAME + " ***"); print(""); print("INPUT_DIR :"+INPUT_DIR); // 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 *************** setBatchMode(true); // Create the output folder OUTPUT_DIR = INPUT_DIR; OUTPUT_PARENT_DIR=File.getParent(OUTPUT_DIR); print("OUTPUT_DIR: "+OUTPUT_DIR); print("OUTPUT_PARENT_DIR: "+OUTPUT_PARENT_DIR); //*************** Processing *************** // Loop on all .tif extensions for (n=0; n-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(FILE_PATH); INPUT_ID = getImageID(); // Beginning of processing part run("Scale...", "x=" + UPS + " y=" + UPS + " interpolation=None average create"); // End of processing part // Get output image ID SCALE_ID = getImageID(); // Case of processing creating a new output image: close the input image if (SCALE_ID != INPUT_ID) { selectImage(INPUT_ID); close(); } // Some processing //Stack.setActiveChannels("1110"); //run("Stack to RGB"); // Get output image ID OUTPUT_ID = getImageID(); // Case of processing creating a new output image: close the input image if (OUTPUT_ID != SCALE_ID) { selectImage(SCALE_ID); close(); } // Create output file path and save the output image selectImage(OUTPUT_ID); OUTPUT_PATH = OUTPUT_DIR + FILE_NAME; save(OUTPUT_PATH); print("OUTPUT_PATH: "+OUTPUT_PATH); // Close output image if checked close(); }// end of if loop on excluded and included strings in name }// end of IF loop on tif extensions }// end of FOR loop on all files setBatchMode("exit and display"); print(""); print("*** " + MAC_NAME + " end ***"); showStatus(MAC_NAME + " finished"); } //*************** Functions *************** function getFileExtension(Name) { nameparts = split(Name, "."); shortname = nameparts[0]; if (nameparts.length > 2) { for (k = 1; k < nameparts.length - 1; k++) { shortname += "." + nameparts[k]; } } extname = "." + nameparts[nameparts.length - 1]; namearray = newArray(shortname, extname); return namearray; }