Skip to main content

Fast Leica LIF file reader written in python

Project description

Documentation Status Test Status

readlif README file

The readlif package was developed to be a fast, python only, reader for Leica Lif files. This is tested in Python 3.6 and 3.7.

The basic premise is to read in an image from a Lif file into a Pillow object. The only additional requirement for this package is Pillow>=4.2.0.

This code is inspired by the Open Microscopy Bio-Formats project.


Everything in this package is numbered starting from 0, which is not consistent with how things like ImageJ operate.

The basic object is the LifFile object.

from readlif.reader import LifFile
new = LifFile('./path/to/file.lif')

This object contains a few methods to access the images contained within the Lif file. All images, in a folder or not, will be accessible sequentially from the LifFile object.

# Access a specific image directly
img_0 = new.get_image(0)
# Create a list of images using a generator
img_list = [i for i in new.get_iter_image()]

The resulting LifImage object has a few methods to access the specific two-dimensional frame contained in the image, where z is the z position, t is the timepoint, and c is the channel.

# Access a specific item
img_0.get_frame(z=0, t=0, c=0)
# Iterate over different items
frame_list   = [i for i in img_0.get_iter_t(c=0, z=0)]
z_list       = [i for i in img_0.get_iter_z(t=0, c=0)]
channel_list = [i for i in img_0.get_iter_c(t=0, z=0)]

The two dimensional images returned by these methods are Pillow objects, so the applicable methods (.show()) will work with them.

This has only been tested on Lif files that were generated with Leica LAS X and Leica LAS AF. There will likely be files that will not work with this software. In that case, please open an issue on github!

Auto-generated documentation is available here.


0.2.1 - Fixed ZeroDivisionError when the Z-dimension is defined, but has a length of 0. Clarified an error message. Added fix for truncated files.

0.2.0 - LifImage.scale now returns px/nm conversions

0.1.1 - Style changes

0.1.0 - Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for readlif, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size readlif-0.2.1-py3.7.egg (14.5 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size readlif-0.2.1-py3-none-any.whl (19.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size readlif-0.2.1.tar.gz (6.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page