Openalea.Image.Serial Package#

Serial.Basics#

openalea.image.serial.basics#

This module redefine load and save to account for spatial images

openalea.image.serial.basics.imread(filename, dimension=3)[source]#

Reads an image file completely into memory.

It uses the file extension to determine how to read the file. It first tries some specific readers for volume images (Inrimages, TIFFs, LSMs, NPY) or falls back on PIL readers for common formats if installed.

In all cases the returned image is 3D (2D is upgraded to single slice 3D). If it has colour or is a vector field it is even 4D.

Parameters:
  • filename (str)

Returns Type:

|SpatialImage|

openalea.image.serial.basics.imsave(filename, img)[source]#

Save a |SpatialImage| to filename.

The filewriter is choosen according to the file extension. However all file extensions will not match the data held by img, in dimensionnality or encoding, and might raise `IOError`s.

For real volume data, Inrimage and NPY are currently supported. For |SpatialImage|s that are actually 2D, PNG, BMP, JPG among others are supported if PIL is installed.

Parameters:
openalea.image.serial.basics.lazy_image_or_path(image)[source]#

Takes an image or a path to an image and returns the image.

Extensively used in other functions to make them accept images given as paths. If image is already a |SpatialImage| this method is a pass-thru. If it looks like a path, it will load the image at that path and return it.

Parameters:
Returns:
  • image or imread(image)

Returns Type:

|SpatialImage|

openalea.image.serial.basics.load(file, mmap_mode=None, is_vectorial=False)[source]#

Load a pickled, .npy, or .npz binary file.

Parameters:
  • file (file or str)

  • mmap_mode (None, ‘r+’, ‘r’, ‘w+’, ‘c’) - optional

    If not None, then memory-map the file, using the given mode (see numpy.memmap). The mode has no effect for pickled or zipped files. A memory-mapped array is stored on disk, and not directly loaded into memory. However, it can be accessed and sliced like any ndarray. Memory mapping is especially useful for accessing small fragments of large files without reading the entire file into memory.

  • is_vectorial (bool) - specifically deal with file as if it was

    a 2D vectorial (RGB[A]) image so that it returns a 3D RGBA image and conforms to the contract.

Returns Type:

|SpatialImage|

openalea.image.serial.basics.read_sequence(directory, grayscale=True, number_images=None, start=0, increment=1, filename_contains='', voxels_size=None, verbose=True)[source]#

Convert a sequence of images in a folder as a numpy array. The images must all be the same size and type. They can be in TIFF, …. format.

Parameters:
  • grayscale (bool) - convert the image to grayscale

  • number_images (int) - specify how many images to open

  • start (int) - used to start with the nth image in the folder (default = 0 for the first image)

  • increment (int) - set to “n” to open every “n” image (default = 1 for opening all images)

  • filename_contains (str) - only files whose name contains that string are opened

  • `voxels_size (tuple) - specify voxels size

  • verbose (bool) - verbose mode

openalea.image.serial.basics.save(filename, img, is_vectorial=False)[source]#

Save an array to a binary file in numpy format with a |SpatialImage| header.

Warning

There is no way to distinguish a 2D RGB[A] image from a 3D scalar image. If img is a 2D RGB[A] image, make sure its shape is similar to (SX,SY,1,3) for RGB or (SX,SY,1,4) for RGBA.

Parameters:
  • filename (file or str) - Filename to which the data is saved.

    If the filename does not already have a “.npy” extension, it is added.

  • img (array)

  • is_vectorial (bool) - specifically deal with img as if it was

    a 2D vectorial (RGB[A]) image so that it saves it as a 3D RGBA image and conforms to the contract.

Serial.Inrimage#

openalea.image.serial.inrimage#

This module defines inrimage format

openalea.image.serial.inrimage.read_inriheader(filename)[source]#

Read only the header of an inrimage

Parameters:

filename – str - name of the file to read

Returns:

prop (dict of str)

openalea.image.serial.inrimage.read_inrimage(filename)[source]#

Read an inrimage, either zipped or not according to extension

Parameters:

filename – str - name of the file to read

Returns:

img (SpatialImage)

openalea.image.serial.inrimage.write_inrimage(filename, img)[source]#

Write an inrimage zipped or not according to the extension

Warning

if img is not a |SpatialImage|, default values will be used for the resolution of the image

Parameters:
  • img|SpatialImage| - image to write

  • filename – str - name of the file to read

Serial.Lsm#

openalea.image.serial.lsm#

This module reads lsm format

Serial.Tif#

openalea.image.serial.tif#

This module reads 3D tiff format