// Dave Barry, Francis Crick Institute // 2018.08.14 // david.barry@crick.ac.uk // Generates "preview" images of stacks in a directory macro "Huygens Browser 2"{ startTime = getTime(); input = getDirectory("Choose Input Directory"); list = getFileList(input); Dialog.create("Huygens Browser"); Dialog.addNumber("Number of images to open:", 3); Dialog.addNumber("Display constrast saturation (0.0 - 1.0):", 0.35); Dialog.addString("File extension:", ".tif"); Dialog.show(); nOpen = Dialog.getNumber(); saturation = Dialog.getNumber(); extension = Dialog.getString(); nSeries = 0; nChannels = 0; series = newArray(list.length); channels = newArray(list.length); Array.fill(series, -1); Array.fill(channels, -1); for(i = 0; i < list.length; i++){ file = input + list[i]; filename = list[i]; if(endsWith(toLowerCase(list[i]), toLowerCase(extension))){ baseFileName = list[i]; s1 = indexOf(filename, "_S"); s2 = lastIndexOf(filename, ".ome_"); c1 = indexOf(filename, "_ch"); c2 = lastIndexOf(filename, ".tif"); s = parseInt(substring(filename, s1+2, s2)); c = parseInt(substring(filename, c1+3, c2)); if(!searchArray(series, s)){ series[nSeries] = s; nSeries++; } if(!searchArray(channels, c)){ channels[nChannels] = c; nChannels++; } } } IJ.log("Number of series: " + nSeries); IJ.log("Number of channels: " + nChannels); count = 0; for (s = 0; s < nSeries; s++){ makePreview(input, baseFileName, series[s], nChannels); count++; if(count >= nOpen){ waitForUser("Huygens Browser", "Press OK to open next " + count + " image(s)."); count = 0; } } print("Done"); function makePreview(input, filename, series, nChannels) { fullFilename = input + filename; run("Bio-Formats Importer", "open=[" + fullFilename + "] autoscale color_mode=Composite group_files rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT dimensions axis_1_number_of_images=1 axis_1_axis_first_image=" + series + " axis_1_axis_increment=1 axis_2_number_of_images=" + nChannels + " axis_2_axis_first_image=0 axis_2_axis_increment=1 contains=[] name=[]"); getDimensions(w,h,channels,s,f); Stack.setSlice(s / 2); for(c = 1; c <= channels; c++){ Stack.setChannel(c); run("Enhance Contrast", "saturated=" + saturation); } } function searchArray(array, entry){ L = lengthOf(array); for(i = 0; i < L; i++){ if(array[i] == entry){ return true; } } return false; } }