This is an old revision of the document!
Table of Contents
Command Line: LIF to Tiff conversion
LIF is a grouped-stack file format containing multiple stacks. One could access each stack by LOCI Bio-Format plugin installed to ImageJ, but when file size is huge and data is in data server, data transfer rate becomes a bottle neck for the progress of work.
TO avoid this, one could do the file conversion via command line. This could be done by "bfconvert" command line tool available from Bio-format web site. Following command will do the job, converting all.
sh /g/almf/software/bftools/bfconvert <filename.lif> converted_%s_%n_C%c.tiff
One missing function with this CL tool is that physical scales in x, y and z are not read out from LIF so that resulting Tiff stacks are devoid of these parameters. In addition, dimensional values such as number of slices per time point, and number of time points are not converted.
For this reason, following shell script was created to transfer physical scales in together with conversion.
sh /g/almf/software/ij/lifcon.sh </full/path/to/file.lif>
This script will extract metadata from LIF, convert each stack to Tiff stack, and set the physical parameters of the image by extracting these values from metadata. Tiff stack will be saved under a newly created directly where the LIF is located. Name of the directory will be
<file.lif>_tifStack
A text file named
<filename.lif>.meta.txt
is also generated, where extracted metadata is stored.
How Metadata is Extracted
Bioformat commandline tool “showinf” is used to save metadata as a text file. Then During the extraction of tiff stacks, physical scales and dimensionality information is extracted from the text and applied to the tiff stack.
Since macro command run(“Properties…”, arg1, arg2) does not work when IJ is headless since Properties command uses AWT. To avoid this, a small plugin (that does not appear in the menu) was created for setting image properties. This plugin is called from macro to set physical scales.
Link for the Image Property setter.
Shell Script lifcon.sh
#!/bin/sh #script for converting Lif file to tif, and set physical scale. # imgfullpath=$1 # path to IJ jar file IJJARS="/g/almf/software/ij" # path to image IMGFILE="${imgfullpath##*/}" IMGPATH="${imgfullpath%/*}" METAFULLPATH="${imgfullpath}.meta.txt" echo ${METAFULLPATH} # Lif converting IJ macro name IJMACRONAME="LifOpenerCUI.ijm" #timer jobstart=$(date +%s) sh /g/almf/software/bftools/showinf -nopix -nocore ${imgfullpath}>${METAFULLPATH} chmod ugo+x ${METAFULLPATH} /usr/struct/bin/java -cp ${IJJARS}/headless.jar:${IJJARS}/ij-1.44h.jar -Djava.awt.headless=true ij.ImageJ -ijpath ${IJ JARS} -batch ${IJJARS}/${IJMACRONAME} ${imgfullpath} # timer jobend=$(date +%s) echo "Time: $((jobend-jobstart)) secs."
bfconvert help
To convert a file between formats, run:
bfconvert [-debug] [-stitch] [-separate] [-merge] [-expand]
[-bigtiff] [-compression codec] [-series series] [-map id]
in_file out_file
-debug: turn on debugging output
-stitch: stitch input files with similar names
-separate: split RGB images into separate channels
-merge: combine separate channels into RGB image
-expand: expand indexed color to RGB
-bigtiff: force BigTIFF files to be written
-compression: specify the codec to use when saving images
-series: specify which image series to convert
-map: specify file on disk to which name should be mapped
If any of the following patterns are present in out_file, they will
be replaced with the indicated metadata value from the input file.
Pattern: Metadata value:
—————————
%s series index
%n series name
%c channel index
%w channel name
%z Z index
%t T index
If any of these patterns are present, then the images to be saved
will be split into multiple files. For example, if the input file
contains 5 Z sections and 3 timepoints, and out_file is
converted_Z%z_T%t.tiff
then 15 files will be created, with the names
converted_Z0_T0.tiff
converted_Z0_T1.tiff
converted_Z0_T2.tiff
converted_Z1_T0.tiff
…
converted_Z4_T2.tiff
Each file would have a single image plane.