modelarrayio.utils.mif_image.MifImage

class modelarrayio.utils.mif_image.MifImage(dataobj, affine, header=None, extra=None, file_map=None)[source]

Nibabel-style image class for MIF (.mif / .mif.gz) files.

Supports reading and writing the MRtrix Image Format, including gzip compression. The public API mirrors standard nibabel images:

img = MifImage.load('image.mif')
data = img.get_fdata()
affine = img.affine

new_img = MifImage(data, affine)
new_img.to_filename('output.mif')
new_img.to_filename('output.mif.gz')

The MIF layout field (e.g. -0,-1,+2) describes which axis varies fastest on disk and in which direction. get_fdata() always returns a C-contiguous array indexed as data[x, y, z, ...] regardless of the on-disk layout.

__init__(dataobj, affine, header=None, extra=None, file_map=None)[source]

Initialize image

The image is a combination of (array-like, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.

Parameters:
  • dataobj (object) – Object containing image data. It should be some object that returns an array from np.asanyarray. It should have a shape attribute or property

  • affine (None or (4,4) array-like) – homogeneous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case, obj.affine also returns None, and the affine as written to disk will depend on the file format.

  • header (None or mapping or header instance, optional) – metadata for this image format

  • extra (None or mapping, optional) – metadata to associate with image that cannot be stored in the metadata of this image type

  • file_map (mapping, optional) – mapping giving file information for this image format

Methods

__init__(dataobj, affine[, header, extra, ...])

Initialize image

as_reoriented(ornt)

Apply an orientation change and return a new image

filespec_to_file_map(filespec)

Make file_map for this class from filename filespec

from_file_map(file_map, *[, mmap, ...])

Load a MIF image from a nibabel file_map dict.

from_filename(filename, *[, mmap, ...])

Class method to create image from filename filename

from_image(img)

Class method to create new instance of own class from img

get_data([caching])

Return image data from image with any necessary scaling applied

get_data_dtype()

get_fdata(caching, ] =, dtype)

Return floating point image data with necessary scaling applied

get_filename()

Fetch the image filename

instance_to_filename(img, filename)

Save img in our own format, to name implied by filename

load(filename, *[, mmap, keep_file_open])

Class method to create image from filename filename

make_file_map([mapping])

Class method to make files holder for this image type

orthoview()

Plot the image using OrthoSlicer3D

path_maybe_image(filename[, sniff, sniff_max])

Return True if filename may be image matching this class

set_data_dtype(dtype)

set_filename(filename)

Sets the files in the object from a given filename

to_file_map([file_map, dtype])

Save the image to the files described by file_map.

to_filename(filename, **kwargs)

Write image to files implied by filename string

uncache()

Delete any cached read of data from proxied data

update_header()

Harmonize header with image data and affine

Attributes

affine

dataobj

files_types

header

in_memory

True when any array data is in memory cache

makeable

ndim

rw

shape

slicer

Slicer object that returns cropped and subsampled images

valid_exts