/** * MRI Image Conversion Tools * Tools for batch-converting lsm or lif images to tif * * Work on a folder containing lif or lsm files * For each file and for each image it contains: * - save the channels each as a tif file * - save the overlay as an RGB tif file * - optional: save stacks as projections * * written 2011 by Volker Baecker (INSERM) at Montpellier RIO Imaging (www.mri.cnrs.fr) * * The Lif2Tif macro is based on the Leica LIF Extractor macro by Christophe LETERRIER (http://christopheleterrier.com/LeterrierSOFT.html) * which is based on the ZStacks Projector macro version 1.1 14/05/2008 */ var helpURL = "http://dev.mri.cnrs.fr/wiki/imagej-macros/Image_Conversion_Tools" var DO_PROJECTION = false; var USE_ALL_SLICES_FOR_PROJECTION = false; var PROJECTION_START_SLICE = 1; var PROJECTION_END_SLICE = 3; var PROJECTION_METHOD = "Max Intensity"; var OUTPUT_SUBFOLDER = "tif" macro "Unused Tool - C037" { } macro "MRI Image Conversion Tools Help Action Tool - C000T4b12?" { run('URL...', 'url='+helpURL); } macro "Lif2Tif Action Tool - C037T0b11LT7b09iTcb09f" { DIR_PATH=getDirectory("Select a directory"); OUTPUT_DIR = DIR_PATH + "/" + OUTPUT_SUBFOLDER; File.makeDirectory(OUTPUT_DIR); print("\\Clear"); print("converting lif file in folder: "+DIR_PATH); // Get all file names ALL_NAMES=getFileList(DIR_PATH); ALL_EXT=newArray(ALL_NAMES.length); // Create extensions array for (i=0; i1 && DO_PROJECTION) doProjection(); currentTitle = getTitle(); index = lastIndexOf(currentTitle, ".lif - "); name = substring(currentTitle, index+7, lengthOf(currentTitle)-2); save(OUTPUT_DIR + "/" + name + " - RGB.tif"); close(); run("Split Channels"); // Loop on each channel (each opened window) for(j=1; j1 && DO_PROJECTION) doProjection(); currentTitle = getTitle(); index = lastIndexOf(currentTitle, ".lif - "); name = substring(currentTitle, index+7, lengthOf(currentTitle)); save(OUTPUT_DIR + "/" + name + " - C" + j + ".tif"); close(); } } } } setBatchMode("exit and display"); showStatus("finished converting lif to tif"); print("finished converting lif to tif"); } macro "Lsm2Tif Action Tool - C037T0b11LT7b09sTcb09m" { DIR_PATH=getDirectory("Select a directory"); OUTPUT_DIR = DIR_PATH + "/" + OUTPUT_SUBFOLDER; File.makeDirectory(OUTPUT_DIR); print("\\Clear"); print("converting lsm file in folder: "+DIR_PATH); // Get all file names ALL_NAMES=getFileList(DIR_PATH); ALL_EXT=newArray(ALL_NAMES.length); // Create extensions array for (i=0; i1 && DO_PROJECTION) doProjection(); currentTitle = getTitle(); name = substring(currentTitle, 0, lengthOf(currentTitle)-6); save(OUTPUT_DIR + "/" + name + " - RGB.tif"); close(); run("Split Channels"); // Loop on each channel (each opened window) for(j=1; j1 && DO_PROJECTION) doProjection(); currentTitle = getTitle(); name = substring(currentTitle, 3, lengthOf(currentTitle)-4); save(OUTPUT_DIR + "/" + name + " - C" + j + ".tif"); close(); } close(); } } setBatchMode("exit and display"); showStatus("finished converting lsm to tif"); print("finished converting lsm to tif"); } function doProjection() { currentTitle = getTitle(); startSlice = PROJECTION_START_SLICE; endSlice = PROJECTION_END_SLICE; if (USE_ALL_SLICES_FOR_PROJECTION) { startSllice = 1; endSlice = SLICE_COUNT; } run("Z Project...", "start=" + startSlice + " stop=" + endSlice +" projection=" + "[" + PROJECTION_METHOD + "]"); selectImage(currentTitle); close(); rename(currentTitle); } macro 'Lif2Tif Action Tool Options' { showOptionsDialog() } macro 'Lsm2Tif Action Tool Options' { showOptionsDialog() } function showOptionsDialog() { Dialog.create("Lif2Tif Options"); Dialog.addCheckbox("do z-projection", DO_PROJECTION); Dialog.addCheckbox("use all slices for projection", USE_ALL_SLICES_FOR_PROJECTION); Dialog.addNumber("start slice for projection", PROJECTION_START_SLICE); Dialog.addNumber("end slice for projection", PROJECTION_END_SLICE); Dialog.addChoice("projection method", newArray("Average Intensity", "Max Intensity", "Min Intensity", "Sum Slices", "Standard Deviation", "Median"), PROJECTION_METHOD); Dialog.show(); DO_PROJECTION = Dialog.getCheckbox(); USE_ALL_SLICES_FOR_PROJECTION = Dialog.getCheckbox(); PROJECTION_START_SLICE = Dialog.getNumber(); PROJECTION_END_SLICE = Dialog.getNumber(); PROJECTION_METHOD = Dialog.getChoice(); }