NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.volumeutils.seek_tell

Next topic

nibabel.volumeutils.working_type

Reggie -- the one

nibabel.volumeutils.shape_zoom_affine

nibabel.volumeutils.shape_zoom_affine(shape, zooms, x_flip=True)

Get affine implied by given shape and zooms

We get the translations from the center of the image (implied by shape).

Parameters :

shape : (N,) array-like

shape of image data. N is the number of dimensions

zooms : (N,) array-like

zooms (voxel sizes) of the image

x_flip : {True, False}

whether to flip the X row of the affine. Corresponds to radiological storage on disk.

Returns :

aff : (4,4) array

affine giving correspondance of voxel coordinates to mm coordinates, taking the center of the image as origin

Examples

>>> shape = (3, 5, 7)
>>> zooms = (3, 2, 1)
>>> shape_zoom_affine((3, 5, 7), (3, 2, 1))
array([[-3.,  0.,  0.,  3.],
       [ 0.,  2.,  0., -4.],
       [ 0.,  0.,  1., -3.],
       [ 0.,  0.,  0.,  1.]])
>>> shape_zoom_affine((3, 5, 7), (3, 2, 1), False)
array([[ 3.,  0.,  0., -3.],
       [ 0.,  2.,  0., -4.],
       [ 0.,  0.,  1., -3.],
       [ 0.,  0.,  0.,  1.]])