/* * Import multiple files using Bio-Formats using last-used settings started from this post by Ellen TA Dobson https://forum.image.sc/t/imagej-macro-processing-using-bioformat/30928 v210805: 1st working version PJL NHMFL, v230615 updated addImageToStack. v230822: Corrected selectImage to selectWindow. */ #@ String (visibility=MESSAGE, value="Bio-Formats_Import_Directory_Using_Previous_v210805.ijm", required=false) msg #@ File (label = "Input directory", style = "directory") inputDirectory #@ String (label = "File suffix", value = ".tif") suffix #@ Boolean (label = "Import into stack?", value=false, persist=true) makeStack #@ Boolean (label = "Use filenames for slice labels?", value=true, persist=true) stackLabels #@ String (label = "Stack title", style = "text field") stackT run("Bio-Formats Macro Extensions"); processFolder(inputDirectory); /* function to scan folders/subfolders/files to find files with correct suffix */ function processFolder(Directory) { fileNames = getFileList(Directory); // Array.print(fileNames); fileNames = Array.sort(fileNames); for (i = 0; i < fileNames.length; i++) { /* sub-folders too */ fileName = fileNames[i]; if(File.isDirectory(inputDirectory + File.separator + fileName)) processFolder(inputDirectory + File.separator + fileName); if(endsWith(fileNames[i], suffix)){ fullPath = "" + inputDirectory + File.separator + fileName; run("Bio-Formats (Windowless)", "open=" + fullPath); /* need to use "+...+" variable input for BF input */ if (makeStack){ tempTitle = getTitle(); if (isOpen(stackT)) { addImageToStack(stackT,tempTitle); selectWindow(tempTitle); close(); } else rename(stackT); if (stackLabels) run("Set Label...", "label=&fileName"); } } } run("Select None"); setSlice(1); } /* ( 8(|) ( 8(|) ASC Functions @@@@@:-) @@@@@:-) */ function addImageToStack(stackName,baseImage) { /* v230614: Added "Select None" */ run("Copy"); selectWindow(stackName); run("Add Slice"); run("Paste"); run("Select None"); selectWindow(baseImage); }