NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.trackvis.TrackvisFile

Next topic

nibabel.trackvis.aff_to_hdr

Reggie -- the one

nibabel.trackvis.aff_from_hdr

nibabel.trackvis.aff_from_hdr(trk_hdr, atleast_v2=None)

Return voxel to mm affine from trackvis header

Affine is mapping from voxel space to Nifti (RAS) output coordinate system convention; x: Left -> Right, y: Posterior -> Anterior, z: Inferior -> Superior.

Parameters:

trk_hdr : mapping

Mapping with trackvis header keys version. If version == 2, we also expect vox_to_ras.

atleast_v2 : None or bool

If None, currently defaults to False. This will change to True in future versions. If True, require that there is a valid ‘vox_to_ras’ affine, raise HeaderError otherwise. If False, look for valid ‘vox_to_ras’ affine, but fall back to best guess from version 1 fields otherwise.

Returns:

aff : (4,4) array

affine giving mapping from voxel coordinates (affine applied on the left to points on the right) to millimeter coordinates in the RAS coordinate system

Notes

Our initial idea was to try and work round the deficiencies of the version 1 format by using the DICOM orientation fields to store the affine. This proved difficult in practice because trackvis (the application) doesn’t allow negative voxel sizes (needed for recording axis flips) and sets the origin field to 0. In future, we’ll raise an error rather than try and estimate the affine from version 1 fields