dipy_brain_mask#

Synopsis#

Unified brain masking workflow supporting multiple methods.

Applies brain masking on each file found by ‘globing’ input_files and saves the results in a directory specified by out_dir.

Usage#

dipy_brain_mask [OPTIONS] input_files

Input Parameters#

  • input_files

    Path to the input volumes. This path may contain wildcards to process multiple inputs at once.

General Options#

  • --method

    Brain masking method. Options are:

    • ‘median_otsu’: Classical median Otsu segmentation, DWI-focused.

    • ‘evac’: Deep learning EVACPlus method, T1-focused.

    • ‘mindgrab’: Deep learning MindGrab method, lightweight and works for all modalities.

    • ‘synthseg’: Deep learning SynthSeg method, works for all modalities.

    (default: mindgrab)

  • --bvalues_files

    Path to the b-values files. Used only for ‘median_otsu’ method. This path may contain wildcards to process multiple inputs at once. (default: None)

  • --b0_threshold

    Threshold to consider a volume as b0. Used only if bvalues_files is provided with ‘median_otsu’ method. (default: 50)

  • --median_radius

    Radius (in voxels) of the applied median filter. Used only for ‘median_otsu’ method. (default: 2)

  • --numpass

    Number of pass of the median filter. Used only for ‘median_otsu’ method. (default: 5)

  • --vol_idx

    1D array representing indices of axis=-1 of a 4D input_volume. From the command line use something like ‘1,2,3-5,7’. Used only for ‘median_otsu’ method. This input is required for 4D volumes if bval files are not provided. If bval files are provided, vol_idx is ignored and b0 volumes are used for mask computation. (default: None)

  • --dilate

    Number of iterations for binary dilation. Used only for ‘median_otsu’ method. (default: None)

  • --finalize_mask

    Whether to remove potential holes or islands. Useful for solving minor errors. Used for ‘median_otsu’, ‘synthseg’ and ‘mindgrab’ methods. (default: True)

  • --save_masked

    Save the masked volume in addition to the mask. (default: False)

  • --use_cuda

    Use CUDA for GPU acceleration. Used only for ‘evac’, ‘synthseg’ and ‘mindgrab’ methods. For ‘mindgrab’, same as device='cuda'. (default: False)

  • --device

    Where to run ‘mindgrab’: ‘auto’, ‘cpu’, ‘webgpu’ or ‘cuda’. ‘auto’ uses any GPU through WebGPU if the wgpu package is installed, otherwise CUDA if PyTorch finds an NVIDIA GPU, otherwise the CPU. Used only for ‘mindgrab’ method. (default: auto)

  • --num_threads

    Number of threads to use on the CPU. If None, the value of the OMP_NUM_THREADS environment variable is used if set, otherwise all available cores. If < 0, the maximal number of threads minus \(|num_threads + 1|\) is used (enter -1 to use as many threads as possible). 0 raises an error. Used only for ‘mindgrab’ method. (default: None)

Output Options#

  • --out_dir

    Output directory. (default: current directory)

  • --out_mask

    Name of the mask volume to be saved. (default: brain_mask.nii.gz)

  • --out_masked

    Name of the masked volume to be saved. (default: brain_masked.nii.gz)

References#

Garyfallidis, E., M. Brett, B. Amirbekian, A. Rokem, S. Van Der Walt, M. Descoteaux, and I. Nimmo-Smith. Dipy, a library for the analysis of diffusion MRI data. Frontiers in Neuroinformatics, 1-18, 2014.