macro "Stack_Kymos" { //*************** Initialization *************** // Get the folder name INPUT_DIR=getDirectory("Select the input stacks directory"); INPUT_NAME = File.getName(INPUT_DIR); PARENT_DIR = File.getParent(INPUT_DIR); PARENT_NAME = File.getName(INPUT_DIR); print("\n\n\n*** Stack Kymos Log ***"); print(""); print("INPUT_DIR: " + INPUT_DIR); print("INPUT_NAME: " + INPUT_NAME); print("PARENT_DIR: " + PARENT_DIR); print("PARENT_NAME: " + PARENT_NAME); // Get all file names ALL_NAMES=getFileList(INPUT_DIR); ALL_EXT=newArray(ALL_NAMES.length); // Create extensions array for (i = 0; i < ALL_NAMES.length; i++) { // print(ALL_NAMES[i]); ALL_NAMES_PARTS = getFileExtension(ALL_NAMES[i]); ALL_EXT[i] = ALL_NAMES_PARTS[1]; } setBatchMode(true); IMcount = 0; IMlast = 0; //*************** Processing *************** // Loop on all .tif extensions for (n=0; n1) { // resize hyperstack if new image is bigger selectImage(hsID); Stack.getDimensions(currW, currH, currC, currS, currF); if (newW > currW || newH > currH) { run("Canvas Size...", "width=" + maxOf(newW, currW) + " height=" + maxOf(newH, currH) + " position=Top-Left zero"); } // add one slice to hyperstack selectImage(hsID); run("Add Slice", "add=slice"); currS = currS + 1; } // copy each channel in new slice for (c = 0; c < newC; c++) { selectImage(inID); Stack.setPosition(c + 1, newS, newF); run("Select All"); run("Copy"); selectImage(hsID); Stack.setPosition(c + 1, currS, currF); setMetadata("Label", label + "-C=" + c); makeRectangle(0, 0, newW, newH); run("Paste"); resetMinAndMax(); run("Select None"); } // close image selectImage(inID); close(); }// end of IF loop on tif extensions }// end of FOR loop on all files Stack.setDisplayMode("composite"); // Create output file path and save the output hyperstack OUTPUT_PATH = PARENT_DIR + File.separator + INPUT_NAME + ".tif"; save(OUTPUT_PATH); print("OUTPUT_PATH: " + OUTPUT_PATH); setBatchMode("exit and display"); print(""); print("*** Stack_Kymos end ***"); showStatus("Stack Kymos 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; }