interfaces.image

Reorient

Link to code

Conform an image to a given orientation

Flips and reorder the image data array so that the axes match the directions indicated in orientation. The default RAS orientation corresponds to the first axis being ordered from left to right, the second axis from posterior to anterior, and the third axis from inferior to superior.

For oblique images, the original orientation is considered to be the closest plumb orientation.

No resampling is performed, and thus the output image is not de-obliqued or registered to any other image or template.

The effective transform is calculated from the original affine matrix to the reoriented affine matrix.

Examples

If an image is not reoriented, the original file is not modified

>>> import numpy as np
>>> from nipype.interfaces.image import Reorient
>>> reorient = Reorient(orientation='LPS')
>>> reorient.inputs.in_file = 'segmentation0.nii.gz'
>>> res = reorient.run()
>>> res.outputs.out_file
'segmentation0.nii.gz'
>>> print(np.loadtxt(res.outputs.transform))
[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]
>>> reorient.inputs.orientation = 'RAS'
>>> res = reorient.run()
>>> res.outputs.out_file  
'.../segmentation0_ras.nii.gz'
>>> print(np.loadtxt(res.outputs.transform))
[[-1.  0.  0. 60.]
 [ 0. -1.  0. 72.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]]

Inputs:

[Mandatory]
in_file: (an existing file name)
        Input image

[Optional]
ignore_exception: (a boolean, nipype default value: False)
        Print an error message instead of throwing an exception in case the
        interface fails to run
orientation: ('RAS' or 'RAI' or 'RPS' or 'RPI' or 'LAS' or 'LAI' or
         'LPS' or 'LPI' or 'RSA' or 'RSP' or 'RIA' or 'RIP' or 'LSA' or
         'LSP' or 'LIA' or 'LIP' or 'ARS' or 'ARI' or 'ALS' or 'ALI' or
         'PRS' or 'PRI' or 'PLS' or 'PLI' or 'ASR' or 'ASL' or 'AIR' or
         'AIL' or 'PSR' or 'PSL' or 'PIR' or 'PIL' or 'SRA' or 'SRP' or
         'SLA' or 'SLP' or 'IRA' or 'IRP' or 'ILA' or 'ILP' or 'SAR' or
         'SAL' or 'SPR' or 'SPL' or 'IAR' or 'IAL' or 'IPR' or 'IPL', nipype
         default value: RAS)
        Target axis orientation

Outputs:

out_file: (an existing file name)
        Reoriented image
transform: (an existing file name)
        Affine transform from input orientation to output