NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.trackvis.aff_from_hdr

Next topic

nibabel.trackvis.empty_header

Reggie -- the one

nibabel.trackvis.aff_to_hdr

nibabel.trackvis.aff_to_hdr(affine, trk_hdr, pos_vox=None, set_order=None)

Set affine affine into trackvis header trk_hdr

Affine is mapping from voxel space to Nifti RAS) output coordinate system convention; x: Left -> Right, y: Posterior -> Anterior, z: Inferior -> Superior. Sets affine if possible, and voxel sizes, and voxel axis ordering.

Parameters:

affine : (4,4) array-like

Affine voxel to mm transformation

trk_hdr : mapping

Mapping implementing __setitem__

pos_vos : None or bool

If None, currently defaults to False - this will change in future versions of nibabel. If False, allow negative voxel sizes in header to record axis flips. Negative voxels cause problems for trackvis (the application). If True, enforce positive voxel sizes.

set_order : None or bool

If None, currently defaults to False - this will change in future versions of nibabel. If False, do not set voxel_order field in trk_hdr. If True, calculcate voxel_order from affine and set into trk_hdr.

Returns:

None :

Notes

version 2 of the trackvis header has a dedicated field for the nifti RAS affine. In theory trackvis 1 has enough information to store an affine, with the fields ‘origin’, ‘voxel_size’ and ‘image_orientation_patient’. Unfortunately, to be able to store any affine, we’d need to be able to set negative voxel sizes, to encode axis flips. This is because ‘image_orientation_patient’ is only two columns of the 3x3 rotation matrix, and we need to know the number of flips to reconstruct the third column reliably. It turns out that negative flips upset trackvis (the application). The application also ignores the origin field, and may not use the ‘image_orientation_patient’ field.