This module redefine load and save to account for spatial images

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.

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|

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

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:
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|

This Page