niftynet.io.image_type module

This module defines images used by image reader, image properties are set by user or read from image header.

class Loadable[source]

Bases: object

interface of loadable data

get_data()[source]

loads a numpy array from the image object if the array has less than 5 dimensions it extends the array to 5d (corresponding to 3 spatial dimensions, temporal dim, modalities) ndims > 5 not currently supported

class DataFromFile(file_path, name=('loadable_data', ), loader=None)[source]

Bases: niftynet.io.image_type.Loadable

Data from file should have a valid file path (are files on hard drive) and a name.

dtype

data type property of the input images.

Returns:a tuple of input image data types len(self.dtype) == len(self.file_path)
file_path

A tuple of valid image filenames, this property always returns a tuple, length of the tuple is one for single image, length of the tuple is larger than one for single image from multiple files.

Returns:a tuple of file paths
loader

A tuple of valid image loaders. Always returns a tuple

name

A tuple of image names, this property always returns a tuple, length of the tuple is one for single image, length of the tuple is larger than one for single image from multiple files.

Returns:a tuple of image name tags
get_data()[source]

loads a numpy array from the image object if the array has less than 5 dimensions it extends the array to 5d (corresponding to 3 spatial dimensions, temporal dim, modalities) ndims > 5 not currently supported

class SpatialImage2D(file_path, name, interp_order, output_pixdim, output_axcodes, loader)[source]

Bases: niftynet.io.image_type.DataFromFile

2D images, axcodes specifications are ignored when loading. (Resampling to new pixdims is currently not supported).

spatial_rank

volume [x, y, 1, m, n] will have a spatial rank 2 volume [x, y, z, m, n] will have a spatial rank 3

if z > 1

(resampling/reorientation will not be done when spatial rank is 2).

original_shape

Shape with multi-modal concatenation, before any resampling.

Returns:a tuple of integers as the original image shape
shape

This function read image shape info from the headers The lengths in the fifth dim of multiple images are summed as a multi-mod representation. The fourth dim corresponding to different time sequences is ignored.

Returns:a tuple of integers as image shape
original_pixdim

pixdim info from the image header.

Returns:a tuple of pixdims, with each element as pixdims of an image file
original_affine

affine info from the image header.

Returns:a tuple of affine, with each element as an affine matrix of an image file
original_axcodes

axcodes info from the image header more info: http://nipy.org/nibabel/image_orientation.html

Returns:a tuple of axcodes, with each element as axcodes of an image file
interp_order

interpolation order specified by user.

Returns:a tuple of integers, with each element as an interpolation order of an image file
dtype

data type property of the input images.

Returns:a tuple of input image data types len(self.dtype) == len(self.file_path)
output_pixdim

output pixdim info specified by user set to None for using the original pixdim in image header otherwise get_data() transforms image array according to this value.

Returns:a tuple of pixdims, with each element as pixdims of an image file
output_axcodes

output axcodes info specified by user set to None for using the original axcodes in image header, otherwise get_data() change axes of the image array according to this value.

Returns:a tuple of pixdims, with each element as pixdims of an image file
get_data()[source]

loads a numpy array from the image object if the array has less than 5 dimensions it extends the array to 5d (corresponding to 3 spatial dimensions, temporal dim, modalities) ndims > 5 not currently supported

class SpatialImage3D(file_path, name, interp_order, output_pixdim, output_axcodes, loader)[source]

Bases: niftynet.io.image_type.SpatialImage2D

3D image from a single, supports resampling and reorientation (3D image from a set of 2D slices is currently not supported).

output_pixdim
output_axcodes
shape
class SpatialImage4D(file_path, name, interp_order, output_pixdim, output_axcodes, loader)[source]

Bases: niftynet.io.image_type.SpatialImage3D

4D image from a set of 3D volumes, supports resampling and reorientation.

The 3D volumes are concatenated in the fifth dim (modality dim)

spatial_rank

Inferring spatial rank from array shape.

In the case of concatenating M volumes of [x, y, 1] the outcome [x, y, 1, 1, M] will have a spatial rank 2 (resampling/reorientation will not be done in this case).

Returns:an integer
get_data()[source]

loads a numpy array from the image object if the array has less than 5 dimensions it extends the array to 5d (corresponding to 3 spatial dimensions, temporal dim, modalities) ndims > 5 not currently supported

class SpatialImage5D(file_path, name, interp_order, output_pixdim, output_axcodes, loader)[source]

Bases: niftynet.io.image_type.SpatialImage4D

5D image from a single file, resampling and reorientation are implemented as operations on each 3D slice individually.

(5D image from a set of 4D files is currently not supported)

class ImageFactory[source]

Bases: object

Create image instance according to number of dimensions specified in image headers.

INSTANCE_DICT = {2: <class 'niftynet.io.image_type.SpatialImage2D'>, 3: <class 'niftynet.io.image_type.SpatialImage3D'>, 4: <class 'niftynet.io.image_type.SpatialImage4D'>, 5: <class 'niftynet.io.image_type.SpatialImage5D'>, 6: <class 'niftynet.io.image_type.SpatialImage5D'>}
classmethod create_instance(file_path, **kwargs)[source]

Read image headers and create image instance.

Parameters:
  • file_path – a file path or a sequence of file paths
  • kwargs – output properties for transforming the image data array into a desired format
Returns:

an image instance