Utilities for running various MRtrix3’s DWI preprocessing tools

designer.preprocessing.mrpreproc.brainmask(input, output, thresh=0.25, nthreads=None, force=False, verbose=False)

Creates a brainmask using FSL’s Brain Extraction Tool (BET) and MRtrix3’s file manipulation tools.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .nii brainmask file

  • thresh (float) – BET threshold ranging from 0 to 1 (Default: 0.25)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.degibbs(input, output, nthreads=None, force=False, verbose=False)

Runs MRtrix3’s mrdegibbs command with optimal parameters for PyDesigner.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.denoise(input, output, noisemap=True, extent='5,5,5', nthreads=None, force=True, verbose=False)

Runs MRtrix3’s dwidenoise command with optimal parameters for PyDesigner.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • noisemap (bool, optional) – Specify whether or not to save the noisemap as a nifti file (Default: True)

  • extent (str, optional) – Set the window size of the denoising filter. (Default: ‘5,5,5’)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.epiboost(input, output, num=1, nthreads=None, force=False, verbose=False)

Analyzes an input .mif’s PE direction to split into two different phase encoding (PE) DWIs. B0s from opposing PE are then extracted and concatenated with the DWI. This reduces the number of B0s used in undistortion for a better and speedier estimation of the distortion field.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • num (int) – Number of B0s pairs to use in EPI correction (Default: 1)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.extractbzero(input, output, nthreads=None, force=False, verbose=False)

Extracts only bzero shells from an input mif file.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.extractmeanbzero(input, output, nthreads=None, force=False, verbose=False)

Extracts average B0 from all B0 shells, with NaNs removed.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif or .nii file

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.extractnonbzero(input, output, nthreads=None, force=False, verbose=False)

Extracts only non-bzero shells from an input mif file.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.miftonii(input, output, strides='1,2,3,4', nthreads=None, force=True, verbose=False)

Converts input .mif images to output .nii images

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .nii file

  • strides (str, optional) – Specify the strides of the output data in memory (Default: ‘1,2,3,4’)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

See also

niitomif()

designer.preprocessing.mrpreproc.niitomif(input, output, strides='1,2,3,4', nthreads=None, force=True, verbose=False)

Converts input .nii images to output .nif images provided that all BVEC, BVAL and JSON files are provided and named same as input .nii

Parameters
  • input (str) – Path to input .nii file

  • output (str) – Path to output .mif file

  • strides (str, optional) – Specify the strides of the output data in memory (Default: ‘1,2,3,4’)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

See also

miftonii()

designer.preprocessing.mrpreproc.reslice(input, output, size, interp='linear', nthreads=None, force=False, verbose=False)

Reslices input image to target voxel size

Parameters
  • input (str) – Path to input file; .mif or .nii

  • output (str) – Path to output file; .mif or .nii

  • size (tuple of float) – x, y, z voxel size in mm or output dimensions.

  • interp (str, {‘linear’, ‘nearest’, ‘cubic’ , ‘sinc’}, optional) – set the interpolation method to use when resizing (Default: ‘linear’)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file

Notes

If any of the axes in size is specified to be over 9 mm, this functions reslices to defined output dimensions, instead of voxel size. This is done to automatically reslice with minimal user input, and also because voxel size beyond 9 mm in unrealistic.

Additionally, if target resolution is the same as input file’s resolution, reslicing is skipped but the output file is still generated.

designer.preprocessing.mrpreproc.riciancorrect(input, output, noise=None)

Performs Rician correction on input .mif

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • noise (str) – Path to noise map from dwidenoise in .nii format (Default: None)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.smooth(input, output, fwhm=1.25)

Performs Gaussian smoothing on input .mif image

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • fwhm (float) – The full width half max in voxels to be smoothed (Default: 1.25)

Returns

Return type

None; writes out file

designer.preprocessing.mrpreproc.undistort(input, output, rpe='rpe_header', epib0=1, qc=None, nthreads=None, force=False, verbose=False)

Runs MRtrix3’s dwipreproc command with optimal parameters for PyDesigner.

Parameters
  • input (str) – Path to input .mif file

  • output (str) – Path to output .mif file

  • rpe (str, {‘rpe_header’, ‘rpe-pair’, ‘rpe_all, ‘rpe_all’}, optional) – Reverse phase encoding of the dataset. (Default: ‘rpe_header’)

  • epib0 (int) – Number of reverse PE dir B0 pairs to use in TOPUP correction (Default: 1)

  • qc (bool) – Specify whether to generate eddy QC metrics (Default: True)

  • nthreads (int, optional) – Specify the number of threads to use in processing (Default: all available threads)

  • force (bool, optional) – Force overwrite of output files if pre-existing (Default:False)

  • verbose (bool, optional) – Specify whether to print console output (Default: False)

Returns

Return type

None; writes out file