// Dave Barry, Francis Crick Institute // 2018.08.14 // david.barry@crick.ac.uk // Generates "preview" images of stacks in a directory macro "Stack Reformatter"{ startTime = getTime(); setBatchMode(true) input = getDirectory("Choose Input Directory"); output = getDirectory("Choose Output Directory"); list = getFileList(input); Dialog.create("Huygens Browser"); Dialog.addNumber("Number of channels:", 3); Dialog.addString("File extension:", ".tif"); Dialog.show(); channels = Dialog.getNumber(); extension = Dialog.getString(); for (i = 0; i < list.length; i++){ if(endsWith(toLowerCase(list[i]), toLowerCase(extension))){ reformat(input, output, list[i], channels); print(round((i + 1) * 100.0 / list.length) + "% done"); } } setBatchMode(false); close("*"); duration = (getTime() - startTime) / 1000; hours = floor(duration / 3600); minutes = floor((duration - hours * 3600) / 60); seconds = floor(duration - hours * 3600 - minutes * 60); print("100% Done: " + hours + ":" + minutes + ":" + seconds); function reformat(input, output, filename, channels) { fullInputFilename = input + filename; fullOutputFilename = output + filename + ".ome.tif"; print ("Reading " + fullInputFilename); run("Bio-Formats Importer", "open=[" + fullInputFilename + "] color_mode=Custom rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT"); slices = nSlices() / channels; run("Stack to Hyperstack...", "order=xyzct channels=" + channels + " slices=" + slices + " frames=1 display=Composite"); print ("Writing " + fullOutputFilename); run("Bio-Formats Exporter", "save=[" + fullOutputFilename + "] compression=LZW"); } }