NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.analyze.AnalyzeHeader

Next topic

nibabel.spm2analyze

Reggie -- the one

nibabel.analyze.AnalyzeImage

digraph inheritance6d2e08605d { rankdir=LR; ratio=compress; fontsize=14; size="6.0, 8.0"; "SpatialImage" [shape=ellipse,URL="nibabel.spatialimages.SpatialImage.html#nibabel.spatialimages.SpatialImage",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "AnalyzeImage" [shape=ellipse,URL="#nibabel.analyze.AnalyzeImage",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "SpatialImage" -> "AnalyzeImage" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

class nibabel.analyze.AnalyzeImage(data, affine, header=None, extra=None, file_map=None)

Initialize image

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

Parameters :

data : object

image data. It should be some object that retuns an array from np.asanyarray. It should have a shape attribute or property

affine : None or (4,4) array-like

homogenous affine giving relationship between voxel coordinates and world coordinates. Affine can also be None. In this case, obj.get_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

ImageArrayProxy

alias of ArrayProxy

files_types = (('image', '.img'), ('header', '.hdr'))
classmethod from_file_map(klass, file_map)

class method to create image from mapping in file_map `

get_data_dtype()
get_header()

Return header

header_class

alias of AnalyzeHeader

set_data_dtype(dtype)
to_file_map(file_map=None)

Write image to file_map or contained self.file_map

Parameters :

file_map : None or mapping, optional

files mapping. If None (default) use object’s file_map attribute instead

update_header()

Harmonize header with image data and affine

>>> data = np.zeros((2,3,4))
>>> affine = np.diag([1.0,2.0,3.0,1.0])
>>> img = AnalyzeImage(data, affine)
>>> hdr = img.get_header()
>>> img.shape
(2, 3, 4)
>>> img.update_header()
>>> hdr.get_data_shape()
(2, 3, 4)
>>> hdr.get_zooms()
(1.0, 2.0, 3.0)