cmtklib.diffusion module

Module that defines CMTK utility functions for the diffusion pipeline.

ExtractPVEsFrom5TT

Link to code

Bases: nipype.interfaces.base.core.BaseInterface

Create Partial Volume Estimation maps for CSF, GM, WM tissues from mrtrix3 5TT image.

Examples

>>> from cmtklib.diffusion import ExtractPVEsFrom5TT
>>> pves = ExtractPVEsFrom5TT()
>>> pves.inputs.in_5tt = 'sub-01_desc-5tt_dseg.nii.gz'
>>> pves.inputs.ref_image = 'sub-01_T1w.nii.gz'
>>> pves.inputs.pve_csf_file = '/path/to/output_csf_pve.nii.gz'
>>> pves.inputs.pve_gm_file = '/path/to/output_gm_pve.nii.gz'
>>> pves.inputs.pve_wm_file = '/path/to/output_wm_pve.nii.gz'
>>> pves.run()  
in_5tta pathlike object or string representing an existing file

Input 5TT (4D) image.

pve_csf_filea pathlike object or string representing a file

CSF Partial Volume Estimation volume estimated from.

pve_gm_filea pathlike object or string representing a file

GM Partial Volume Estimation volume estimated from.

pve_wm_filea pathlike object or string representing a file

WM Partial Volume Estimation volume estimated from.

ref_imagea pathlike object or string representing an existing file

Reference 3D image to be used to save 3D PVE volumes.

partial_volume_filesa list of items which are a pathlike object or string representing a file

CSF/GM/WM Partial Volume Estimation images estimated from.

FlipBvec

Link to code

Bases: nipype.interfaces.base.core.BaseInterface

Return a diffusion bvec file with flipped axis as specified by flipping_axis input.

Examples

>>> from cmtklib.diffusion import FlipBvec
>>> flip_bvec = FlipBvec()
>>> flip_bvec.inputs.bvecs = 'sub-01_dwi.bvecs'
>>> flip_bvec.inputs.flipping_axis = ['x']
>>> flip_bvec.inputs.delimiter = ' '
>>> flip_bvec.inputs.header_lines = 0
>>> flip_bvec.inputs.orientation = 'h'
>>> flip_bvec.run()  
bvecsa pathlike object or string representing an existing file

Input diffusion gradient bvec file.

delimitera string

Delimiter used in the table.

flipping_axisa list of items which are any value

List of axis to be flipped.

header_linesan integer

Line number of table header.

orientation‘v’ or ‘h’

Orientation of the table.

bvecs_flippeda pathlike object or string representing an existing file

Output bvec file with flipped axis.

FlipTable

Link to code

Bases: nipype.interfaces.base.core.BaseInterface

Flip axis and rewrite a gradient table.

Examples

>>> from cmtklib.diffusion import FlipTable
>>> flip_table = FlipTable()
>>> flip_table.inputs.table = 'sub-01_mod-dwi_gradient.txt'
>>> flip_table.inputs.flipping_axis = ['x']
>>> flip_table.inputs.orientation = 'v'
>>> flip_table.inputs.delimiter = ','
>>> flip_table.run()  
delimitera string

Delimiter used in the table.

flipping_axisa list of items which are any value

List of axis to be flipped.

header_linesan integer

Line number of table header.

orientation‘v’ or ‘h’

Orientation of the table.

tablea pathlike object or string representing an existing file

Input diffusion gradient table.

tablea pathlike object or string representing an existing file

Output table with flipped axis.

Tck2Trk

Link to code

Bases: nipype.interfaces.base.core.BaseInterface

Convert a tractogram in mrtrix TCK format to trackvis TRK format.

Examples

>>> from cmtklib.diffusion import Tck2Trk
>>> tck_to_trk = Tck2Trk()
>>> tck_to_trk.inputs.in_tracks = 'sub-01_tractogram.tck'
>>> tck_to_trk.inputs.in_image = 'sub-01_desc-preproc_dwi.nii.gz'
>>> tck_to_trk.inputs.out_tracks = 'sub-01_tractogram.trk'
>>> tck_to_trk.run()  
in_imagea pathlike object or string representing an existing file

Input image used to extract the header.

in_tracksa pathlike object or string representing an existing file

Input track file in MRtrix .tck format.

out_tracksa pathlike object or string representing a file

Output track file in Trackvis .trk format.

out_tracksa pathlike object or string representing an existing file

Output track file in Trackvis .trk format.

UpdateGMWMInterfaceSeeding

Link to code

Bases: nipype.interfaces.base.core.BaseInterface

Add extra Lausanne2018 structures to the Gray-matter/White-matter interface for tractography seeding.

Examples

>>> from cmtklib.diffusion import UpdateGMWMInterfaceSeeding
>>> update_gmwmi = UpdateGMWMInterfaceSeeding()
>>> update_gmwmi.inputs.in_gmwmi_file = 'sub-01_label-gmwmi_desc-orig_dseg.nii.gz'
>>> update_gmwmi.inputs.out_gmwmi_file = 'sub-01_label-gmwmi_desc-modif_dseg.nii.gz'
>>> update_gmwmi.inputs.in_roi_volumes = ['sub-01_space-DWI_atlas-L2018_desc-scale1_dseg.nii.gz',
>>>                                       'sub-01_space-DWI_atlas-L2018_desc-scale2_dseg.nii.gz',
>>>                                       'sub-01_space-DWI_atlas-L2018_desc-scale3_dseg.nii.gz',
>>>                                       'sub-01_space-DWI_atlas-L2018_desc-scale4_dseg.nii.gz',
>>>                                       'sub-01_space-DWI_atlas-L2018_desc-scale5_dseg.nii.gz']
>>> update_gmwmi.run()  
in_gmwmi_filea pathlike object or string representing an existing file

Input GMWM interface image used for streamline seeding.

in_roi_volumesa list of items which are a pathlike object or string representing an existing file

Input parcellation images.

out_gmwmi_filea pathlike object or string representing a file

Output GM WM interface used for streamline seeding.

out_gmwmi_filea pathlike object or string representing an existing file

Output GM WM interface used for streamline seeding.

cmtklib.diffusion.compute_length_array(trkfile=None, streams=None, savefname='lengths.npy')[source]

Computes the length of the fibers in a tractogram and returns an array of length.

Parameters
  • trkfile (TRK file) – Path to the tractogram in TRK format

  • streams (the fibers data) – The fibers from which we want to compute the length

  • savefname (string) – Output filename to write the length array

Returns

fibers_length – Array of fiber lengths

Return type

numpy.array

cmtklib.diffusion.filter_fibers(intrk, outtrk='', fiber_cutoff_lower=20, fiber_cutoff_upper=500)[source]

Filters a tractogram based on lower / upper cutoffs.

Parameters
  • intrk (TRK file) – Path to a tractogram file in TRK format

  • outtrk (TRK file) – Output path for the filtered tractogram

  • fiber_cutoff_lower (int) – Lower number of fibers cutoff (Default: 20)

  • fiber_cutoff_upper (int) – Upper number of fibers cutoff (Default: 500)