PIMS: Python Image Sequence

PIMS is a lazy-loading interface to sequential data with numpy-like slicing.

Key features:

  • One consistent interface to many file formats
  • Numpy-like slicing returns lazy-loading, iterable, sliceable objects

Example

Everything is demonstrated in this IPython notebook.

Load a sequence of images from a directory, where the images are named img-0.png, img-1.png, etc.

In [1]: from pims import ImageSequence

In [2]: images = ImageSequence('img-*.png')

In [3]: images
Out[3]: 
<Frames>
Source: D:\Casper\Documents\GitHub\pims\doc\img-*.png
Length: 9 frames
Frame Shape: (256, 256)
Pixel Datatype: uint8

Images can be randomly accessed with standard Python slicing syntax.

In [4]: images[0]  # first image
Out[4]: 
Frame([[101,  64, 104, ..., 112,  56, 226],
       [  3, 230, 233, ..., 173, 192, 135],
       [100,  36, 143, ..., 231, 238,  78],
       ..., 
       [175, 186,  55, ..., 143, 229,  60],
       [231,  33, 219, ...,  79, 253, 240],
       [225, 186,  13, ...,   7, 146, 246]], dtype=uint8)

In [5]: images[-5]  # fifth from the end
Out[5]: 
Frame([[ 28,  69, 163, ...,  15,  15,  85],
       [ 95, 119,  94, ...,  15,  78,  92],
       [177,  54,  73, ...,  83, 167,   7],
       ..., 
       [ 91, 246, 190, ...,  36, 124,  85],
       [ 58,  18, 139, ..., 229, 246,  82],
       [ 52,  22, 158, ...,  11,  28,  43]], dtype=uint8)

The images are iterable. Data is loaded one image at a time, conserving memory.

In [6]: import numpy as np

In [7]: for image in images:
   ...:     np.sum(image)  # do something
   ...: 

Slicing images returns another lazy-loading object that is also iterable and sliceable.

In [8]: subsection = images[:5]  # the first five images

In [9]: len(images)
Out[9]: 9

In [10]: len(subsection)
Out[10]: 5

In [11]: for image in subsection:
   ....:     np.sum(image)  # do something
   ....: 

In [12]: subsubsection = subsection[::2]  # every other of the first five images

Fancy numpy-like slicing is supported.

In [13]: subsection2 = images[[0, 3, 7]]

In [14]: mask = [True, False, False, False, False, True, False, False, False, False]

In [15]: subsection3 = images[mask]

Core Contributors

  • Daniel Allan founding contributor, slicing and iteration logic, basic readers, display tools
  • Thomas Caswell major refactor, abstract base class
  • Casper van der Wel bioformats readers, display tools
  • Thomas Dimiduk filetype-detecting dispatch logic

Support

This package was developed in part 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. Later work was supported by Brookhaven National Lab. Dan can be reached at dallan@bnl.gov.

This package was developed in part by Thomas A Caswell as part of his PhD thesis work in Sidney R Nagel’s and Margaret L Gardel’s groups at the University of Chicago, Chicago IL. This work was supported in part by NSF Grant DMR-1105145 and NSF-MRSEC DMR-0820054. Later work was supported by Brookhaven National Lab. Tom can be reached at tcaswell@gmail.com.

This package was developed in part by Casper van der Wel, as part of his PhD thesis work in Daniela Kraft’s group at the Huygens-Kamerlingh-Onnes laboratory, Institute of Physics, Leiden University, The Netherlands. This work was supported by the Netherlands Organisation for Scientific Research (NWO/OCW).