Thursday, January 29, 2015

Using PyLibTiff to read tiff files in Python

ImageJ can open and save .tiff image stacks with ease. Additionally, to use BrainAligner to register image stacks, it is useful to have the image stacks saved as .tiff files. (My post about BrainAligner is here.) Various Python libraries exist that can open .tiff files, but some of them cannot handle image stacks (3d arrays of pixels). I've started to use PyLibTiff to handle this file type in my Python scripts. In order to install it, just run

sudo apt-get install python-libtiff

at a terminal.

Update: This does not appear to work in Ubuntu 14.04. It results in installation of version 0.3.0, which I believe has been replaced by 0.4.0. You can download the newest version at https://pypi.python.org/pypi/libtiff/ then unpack it, cd to the directory, and run

sudo python setup.py install

For some reason you will need to move out of the downloaded directory in order to actually test it, though. Open a python interactive prompt and make sure that you can import it: from libtiff import TIFF
Below is a snippet of some code that I've been using to open a 2-channel (2-color) image stack and arrange the dimensions in a way that I find intuitive (x,y,z,color).


No comments: