# nipype.interfaces.image module¶

## Reorient¶

Bases: SimpleInterface

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_affine(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_affine(np.loadtxt(res.outputs.transform))
-1.   0.   0.  60.
0.  -1.   0.  72.
0.   0.   1.   0.
0.   0.   0.   1.

Mandatory Inputs

in_file (a pathlike object or string representing an existing file) – Input image.

Optional Inputs

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’) – Target axis orientation. (Nipype default value: RAS)

Outputs
• out_file (a pathlike object or string representing an existing file) – Reoriented image.

• transform (a pathlike object or string representing an existing file) – Affine transform from input orientation to output.

## Rescale¶

Bases: SimpleInterface

Rescale an image

Rescales the non-zero portion of in_file to match the bounds of the non-zero portion of ref_file. Reference values in the input and reference images are defined by the percentile parameter, and the reference values in each image are identified and the remaining values are scaled accordingly. In the case of percentile == 0, the reference values are the maxima and minima of each image. If the invert parameter is set, the input file is inverted prior to rescaling.

Examples

To use a high-resolution T1w image as a registration target for a T2* image, it may be useful to invert the T1w image and rescale to the T2* range. Using the 1st and 99th percentiles may reduce the impact of outlier voxels.

>>> from nipype.interfaces.image import Rescale
>>> invert_t1w = Rescale(invert=True)
>>> invert_t1w.inputs.in_file = 'structural.nii'
>>> invert_t1w.inputs.ref_file = 'functional.nii'
>>> invert_t1w.inputs.percentile = 1.
>>> res = invert_t1w.run()

Mandatory Inputs
• in_file (a pathlike object or string representing an existing file) – Skull-stripped image to rescale.

• ref_file (a pathlike object or string representing an existing file) – Skull-stripped reference image.

Optional Inputs
• invert (a boolean) – Invert contrast of rescaled image.

• percentile (0.0 <= a floating point number <= 50.0) – Percentile to use for reference to allow for outliers - 1 indicates the 1st and 99th percentiles in the input file will be mapped to the 99th and 1st percentiles in the reference; 0 indicates minima and maxima will be mapped. (Nipype default value: 0.0)

Outputs

out_file (a pathlike object or string representing an existing file) – Rescaled image.