niworkflows.interfaces.nibabel module

Nibabel-based interfaces.

class niworkflows.interfaces.nibabel.ApplyMask(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Mask the input given a mask.

Mandatory Inputs:
  • in_file (a pathlike object or string representing an existing file) – An image.

  • in_mask (a pathlike object or string representing an existing file) – A mask.

Optional Inputs:

threshold (a float) – A threshold to the mask, if it is nonbinary. (Nipype default value: 0.5)

Outputs:

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

class niworkflows.interfaces.nibabel.Binarize(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Binarizes the input image applying the given thresholds.

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

  • thresh_low (a float) – Non-inclusive lower threshold.

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

  • out_mask (a pathlike object or string representing an existing file) – Output mask.

class niworkflows.interfaces.nibabel.BinaryDilation(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Morphological binary dilation using Scipy.

Mandatory Inputs:

in_file (a pathlike object or string representing an existing file) – Binary file to dilate.

Optional Inputs:
  • iterations (an integer >= 0) – Repeat dilation. (Nipype default value: 1)

  • radius (a float) – Structure element (ball) radius. (Nipype default value: 3)

Outputs:

out_file (a pathlike object or string representing an existing file) – The input file, after binary dilation.

class niworkflows.interfaces.nibabel.DemeanImage(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Mandatory Inputs:
  • in_file (a pathlike object or string representing an existing file) – Image to be demeaned.

  • in_mask (a pathlike object or string representing an existing file) – Mask where median will be calculated.

Optional Inputs:

only_mask (a boolean) – Demean only within mask. (Nipype default value: False)

Outputs:

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

class niworkflows.interfaces.nibabel.FilledImageLike(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Mandatory Inputs:

in_file (a pathlike object or string representing an existing file) – Image to be demeaned.

Optional Inputs:
  • dtype (‘float32’ or ‘uint8’) – Force output data type. (Nipype default value: float32)

  • fill_value (a float) – Value to fill. (Nipype default value: 1.0)

Outputs:

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

class niworkflows.interfaces.nibabel.GenerateSamplingReference(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Generates a reference grid for resampling one image keeping original resolution, but moving data to a different space (e.g. MNI).

If the fov_mask optional input is provided, then the abbr:FoV (field-of-view) is cropped to a bounding box containing the brain mask plus an offset of two voxels along all dimensions. The fov_mask should be to the brain mask calculated from the T1w, and should not contain the brain stem. The mask is resampled into target space, and then the bounding box is calculated. Finally, the FoV is adjusted to that bounding box.

Mandatory Inputs:
  • fixed_image (a pathlike object or string representing an existing file) – The reference file, defines the FoV.

  • moving_image (a pathlike object or string representing an existing file) – The pixel size reference.

Optional Inputs:
  • fov_mask (a pathlike object or string representing an existing file or None) – Mask to clip field of view (in fixed_image space). (Nipype default value: None)

  • keep_native (a boolean) – Calculate a grid with native resolution covering the volume extent given by fixed_image, fast forward fixed_image otherwise. (Nipype default value: True)

  • xform_code (None or 2 or 4) – Force xform code. (Nipype default value: None)

Outputs:

out_file (a pathlike object or string representing an existing file) – One file with all inputs flattened.

class niworkflows.interfaces.nibabel.IntensityClip(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Clip the intensity range as prescribed by the percentiles.

Mandatory Inputs:

in_file (a pathlike object or string representing an existing file) – 3D file which intensity will be clipped.

Optional Inputs:
  • dtype (‘int16’ or ‘float32’ or ‘uint8’) – Output datatype. (Nipype default value: int16)

  • invert (a boolean) – Finalize by inverting contrast. (Nipype default value: False)

  • nonnegative (a boolean) – Whether input intensities must be positive. (Nipype default value: True)

  • p_max (a float) – Percentile for the upper bound. (Nipype default value: 99.98)

  • p_min (a float) – Percentile for the lower bound. (Nipype default value: 35.0)

Outputs:

out_file (a pathlike object or string representing an existing file) – File after clipping.

class niworkflows.interfaces.nibabel.MapLabels(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Remap discrete labels

Optional Inputs:
  • in_file (a pathlike object or string representing an existing file) – Segmented NIfTI.

  • mappings (a dictionary with keys which are any value and with values which are any value) – Dictionary of label / replacement label pairs. Mutually exclusive with inputs: mappings_file.

  • mappings_file (a pathlike object or string representing an existing file) – Mutually exclusive with inputs: mappings.

Outputs:

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

class niworkflows.interfaces.nibabel.MergeROIs(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Combine multiple region of interest files (3D or 4D) into a single file

Optional Inputs:

in_files (a list of items which are a pathlike object or string representing an existing file) – ROI files to be merged.

Outputs:

out_file (a pathlike object or string representing an existing file) – NIfTI containing all ROIs.

class niworkflows.interfaces.nibabel.MergeSeries(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Merge a series of 3D volumes along the last dimension into a single 4D image.

Optional Inputs:
  • affine_tolerance (a float) – Absolute tolerance allowed between image affines.

  • allow_4D (a boolean) – Whether 4D images are allowed to be concatenated. (Nipype default value: True)

  • in_files (a list of items which are a pathlike object or string representing an existing file)

Outputs:

out_file (a pathlike object or string representing an existing file) – Output 4d image.

class niworkflows.interfaces.nibabel.RegridToZooms(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Change the resolution of an image (regrid).

Mandatory Inputs:
  • in_file (a pathlike object or string representing an existing file) – A file whose resolution is to change.

  • zooms (a tuple of the form: (a float, a float, a float)) – The new resolution.

Optional Inputs:
  • clip (a boolean) – Clip the data array within the original image’s range. (Nipype default value: True)

  • order (an integer) – Order of interpolator. (Nipype default value: 3)

  • smooth (a boolean or a float) – Apply gaussian smoothing before resampling. (Nipype default value: False)

Outputs:

out_file (a pathlike object or string representing an existing file)

class niworkflows.interfaces.nibabel.ReorientImage(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Mandatory Inputs:

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

Optional Inputs:
  • target_file (a pathlike object or string representing an existing file) – Reference file to reorient to. Mutually exclusive with inputs: target_orientation.

  • target_orientation (a string) – Axis codes of coordinate system to reorient to. Mutually exclusive with inputs: target_file.

Outputs:

out_file (a pathlike object or string representing a file) – Reoriented file.

class niworkflows.interfaces.nibabel.SplitSeries(from_file=None, resource_monitor=None, **inputs)[source]

Bases: SimpleInterface

Split a 4D dataset along the last dimension into a series of 3D volumes.

Mandatory Inputs:

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

Outputs:

out_files (a list of items which are a pathlike object or string representing an existing file) – Output list of 3d images.

niworkflows.interfaces.nibabel.reorient_file(in_file: str, *, target_file: str | None = None, target_ornt: str | None = None, newpath: str | None = None) str[source]

Reorient an image.

New orientation targets can be either another image, or a string representation of the orientation axis.

Parameters:
  • in_file (Image to be reoriented)

  • target_file (Reference image of desired orientation)

  • target_ornt (Orientation denoted by the first letter of each axis (i.e., “RAS”, “LPI”))

niworkflows.interfaces.nibabel.reorient_image(img: SpatialImage, target_ornt: str)[source]

Reorient an image in memory.