Saturday, January 31, 2015

Using pynrrd to read nrrd files into Python

Another in the series of posts about file types! This time, a quick note about importing .nrrd image stacks into Python. Download and unzip pynrrd from here. In a terminal, cd into the directory, and run

python setup.py install

In Python the usage is very straightforward:

import nrrd
frames, options = nrrd.read(fileName)


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).


Thursday, January 8, 2015

Two important contributions

Are flies cool?



Are animated GIFs a waste of time?

Wednesday, January 7, 2015

Using pyLSM to read LSM files in Python

The good people at Janelia have provided the fly community with an enormous wealth of data in the form of confocal stacks of their GAL4 collection. There are many excellent open source tools to work with such image collections (e.g. imagej and fluorender), but reading the stacks directly into Python for automated analysis can be difficult. Below I'll describe my preferred method.

First, download the zipped PyLSM folder from here. (Linked to from this page.)

Next, unzip the folder, navigate inside it at a command prompt, and run

sudo python setup.py install

The website for this python module is http://www.freesbi.ch/en/pylsm and there is some documentation here.

I haven't tried out the gui yet, but here is a snippet of code that should open a Janelia stack.