Scientific video can be packaged in various ways: familiar video formats like .AVI and .MOV, folders full of numbered images, or "stacks" of TIFF images. Each of these requires a separate Python module. And, once loaded, they have different methods for accessing individual images, looping through the images in bulk, or access a specific range. PIMS can do all of these using a consistent interface, handling the differences between different inputs invisibly.
Everything is demonstrated in this IPython notebook.
PIMS depends on numpy and slicerator.
For basic image reading one of the following is required:
Depending on what file formats you want to read, you will also need:
- ffmpeg and PyAV (video formats such as AVI, MOV)
- jpype (interface with bioformats to support many microscopy formats)
- Pillow (improved TIFF support)
- libtiff (alternative TIFF support)
- tifffile (alterative TIFF support)
- pims_nd2 (improved Nikon .nd2 support)
Installation is simple on Windows, OSX, and Linux, even for Python novices.
To get started with Python on any platform, download and install Anaconda. It comes with the common scientific Python packages built in.
Open a command prompt. That's "Terminal" on a Mac, and "Start > Applications > Command Prompt" on Windows. Type these lines:
conda update conda
conda install numpy matplotlib scikit-image pillow
conda install pip
Then, to install pims:
pip install pims
Finally, to try it out, type:
ipython notebook
PIMS can read most TIFF files out of the box, so you should try reading
you files (open('my_tiff_file.tif')
and revisit this section if you
encounter an error. Many camera and software manufacturers have their
own special variants of the TIFF format. Our default reader, built around
Christoph Gohlke's tifffile.py, handles all the formats we have personally enountered. But we have
alternative TIFF readers built around
Pillow (see above) and libtiff, which can be installed like so:
pip install libtiff
To load video files directly, you need FFmpeg or libav. These can be tricky to install, especially on Windows, so we advise less sophisticated users to simply work around this requirement by converting their video files to folders full of images using a utility like ImageJ.
But if either FFmpeg or libav is available, PIMS enables fast random access to video files. It relies on PyAV, which can be installed like so:
pip install av
Bio-Formats is an open-source java library for reading and writing multidimensional image data, especially from microscopy files. To interface with the java library, we use JPype which allows fast and easy access to all java functions. JRE or JDK are not required. Install JPype as follows:
pip install jpype1
On first use of pims.Bioformats(filename)
, the required java library
loci_tools.jar
will be automatically downloaded from
openmicroscopy.org.
If you use conda / Anaconda, watch out for an error like:
version `GLIBC_2.15' not found
This seems to be because conda includes an old version of a library needed by PyAV. To work around this, simply delete anaconda's version of the library:
rm ~/anaconda/lib/libm.so.6
and/or
rm ~/anaconda/envs/name_of_your_environment/lib/libm.so.6
which will cause PyAV to use the your operating system's version of the library.
The code is under active development. To update to the current development version, run this in the command prompt:
pip install --upgrade http://github.com/soft-matter/pims/zipball/master
- Daniel B. Allan
- Thomas A. Caswell
- Casper van der Wel
This package was originally developed and maintained by Daniel Allan, as part of his PhD thesis work on microrheology in Robert L. Leheny's group at Johns Hopkins University in Baltimore, MD. The work was supported by the National Science Foundation under grant number CBET-1033985.
Dan can be reached at daniel.b.allan@jhu.edu.