NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.orientations.flip_axis

Next topic

nibabel.orientations.orientation_affine

This Page

Reggie -- the one

nibabel.orientations.io_orientation

nibabel.orientations.io_orientation(affine, tol=None)

Orientation of input axes in terms of output axes for affine

Valid for an affine transformation from m dimensions to n dimensions (affine.shape == (n+1, m+1)).

The calculated orientations can be used to transform associated arrays to best match the output orientations. If n > m, then some of the output axes should be considered dropped in this orientation.

Parameters :

affine : (n+1,m+1) ndarray-like

Transformation affine from m inputs to n outputs. Usually this will be a shape (4,4) matrix, transforming 3 inputs to 3 outputs, but the code also handles the more general case

tol : {None, float}, optional

threshold below which SVD values of the affine are considered zero. If tol is None, and S is an array with singular values for affine, and eps is the epsilon value for datatype of S, then tol set to S.max() * eps.

Returns :

orientations : (n,2) ndarray

one row per input axis, where the first value in each row is the closest corresponding output axis, and the second value is 1 if the input axis is in the same direction as the corresponding output axis, , and -1 if it is in the opposite direction, to the corresponding output axis. If a row is [np.nan, np.nan], which can happen when n > m, then this row should be considered dropped.