[Neuroimaging] voxel axes reorientation

Christopher Markiewicz effigies at bu.edu
Thu Oct 12 10:45:45 EDT 2017


The basics are this:

img = nib.load(fname)
orig_ornt = nib.orientations.io_orientation(img.affine)
targ_ornt = nib.orientations.axcodes2ornt('LAS')
ornt_xfm = nib.orientations.ornt_transform(orig_ornt, targ_ornt)

If you're using the latest master, you can simply do:

img_LAS = img.as_reoriented(ornt_xfm)

Otherwise, you'll need to transform the data and the affine:

data = nib.orientations.apply_orientation(img.dataobj, ornt_xfm)
affine = img.affine.dot(nib.orientations.inv_ornt_aff(ornt_xfm, img.shape))
img_LAS = img.__class__(data, affine, img.header)

(You should obviously check my work.)

Chris


On Wed, Oct 4, 2017 at 6:16 PM, Vinit Srivastava <
vinit.k.srivastava at gmail.com> wrote:

> Hi,
>
> I've been using nib.as_closest_canonical to reorient the voxel axes to
> RAS+.
>
> Is there an optio to reorient images to a chosen format other than
> canonical RAS format?  For example, I'd like to reorient from LPS to LAS.
>
> Thanks,
>
> Vinny
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20171012/41067a7f/attachment.html>


More information about the Neuroimaging mailing list