Skip to main content

Neural network-based preprocessing of MRI data: Prepping brain images in seconds 🔥

Project description

Disclaimer: deepmriprep is not related to fMRIPrep or sMRIPrep and is not part of the NiPreps framework

logo

deepmriprep runs all preprocessing steps needed for Voxel-based Morphometry (VBM) of T1w MR images:

  • brain extraction (via deepbet)
  • affine registration (via torchreg)
  • tissue segmentation
  • nonlinear registration
  • smoothing

Using neural networks, it only takes ~10 seconds on a GPU (~100 seconds without a GPU) per image 🔥

main_fig

Additionally, deepmriprep can also run atlas registration needed for Region-based Morphometry (RBM).

atlases_small

Installation 🛠️

For GPU-acceleration (NVIDIA needed), PyTorch should be installed first via the proper install command 🔥

deepmriprep can be easily installed via

pip install deepmriprep

The deepmriprep-gui can look grainy in conda environments. To fix that run

conda install -c conda-forge tk=*=xft_*

Usage 💡

After installation, there are three ways to use deepmriprep

  1. deepmriprep-gui runs the Graphical User Interface (GUI)

gui

  1. deepmriprep-cli runs the Command Line Interface (CLI)
deepmriprep-cli -bids path/to/bids
  1. Run deepmriprep directly in Python
from deepmriprep import run_preprocess

# Apply to BIDS dir. (saves to 'path/to/bids/derivatives')
run_preprocess(bids_dir='path/to/bids')
# Apply to list of files and save to output directory
input_paths = ['path/to/input/sub-1_t1w.nii.gz', 'path/to/input/sub-2_t1w.nii.gz']
run_preprocess(input_paths, output_dir='path/to/output')
# Apply to list of files and save to custom output filepaths
output_paths = [{'tiv': 'outpath1/tivsub-1_t1w.csv', 'p0': 'outpath2/p0sub-1_t1w.nii'},
                {'tiv': 'outpath3/tivsub-2_t1w.csv', 'p0': 'outpath4/p0sub-2_t1w.nii'}]
run_preprocess(input_paths, output_paths=output_paths)

Besides the three shown options to specify input and output paths, run_preprocess has the arguments

  • outputs: Output modalities which can be either 'all', 'vbm', 'rbm' or a custom list of output strings
  • dir_format: Output directory structure which can be either 'sub', 'mod', 'cat' or 'flat'
  • no_gpu: Avoids GPU utilization if set to True (set to False per default for GPU-acceleration 🔥)

outputs set to

  • 'all' all output modalities are saved
  • 'vbm' the outputs tiv, mwp1, mwp2, s6mwp1 and s6mwp2 (+affine_loss&warp_mse, for QC) are saved
  • 'rbm' all available atlases (including regions tissue volumes +affine_loss&warp_mse, for QC) are saved

If output_dir is set, dir_format set to

  • 'sub' results in e.g. 'outpath/sub-1/tivsub-1.csv' and 'outpath/sub-1/p0sub-1.nii.gz'
  • 'mod' results in e.g. 'outpath/tiv/tivsub-1.csv' and 'outpath/p0/p0sub-1.nii.gz'
  • 'cat' results in e.g. 'outpath/sub-1/label/tivsub-1.csv' and 'outpath/sub-1/mri/p0sub-1.nii.gz'
  • 'flat' results in e.g. 'outpath/tivsub-1.csv' and 'outpath/p0sub_1.nii.gz'

Quality Control 🔍

Use NiftiView to quickly quality check outputs via patterns like

/path/to/bids/derivatives/deepmriprep/sub*/anat/mri/p0sub*.ni*

in the "Image files" field (all p0 files in this example).

Sort deepmriprep_outputs.csv by affine_loss and warp_mse, since high values can indicate low quality!

Tutorial 🧑‍🏫

In short, deepmriprep (consisting of only ~500 lines of code) internally calls the .run method of the Preprocess class, which sequentially calls the methods .run_bet to .run_atlas_register (see deepmriprep/preprocess.py).

Click here to view the tutorial and get a more detailed look behind the scenes 👀

Citation ©️

If you use deepmriprep in your research, please cite:

@inproceedings{deepmriprep,
Author = {Lukas Fisch, Nils R. Winter, Janik Goltermann, Carlotta Barkhau, Daniel Emden, Jan Ernsting, Maximilian Konowski, Ramona Leenings, Tiana Borgers, Kira Flinkenflügel, Dominik Grotegerd, Anna Kraus, Elisabeth J. Leehr, Susanne Meinert, Frederike Stein, Lea Teutenberg, Florian Thomas-Odenthal, Paula Usemann, Marco Hermesdorf, Hamidreza Jamalabadi, Andreas Jansen, Igor Nenadic, Benjamin Straube, Tilo Kircher, Klaus Berger, Benjamin Risse, Udo Dannlowski, Tim Hahn},
Title = {deepmriprep: Voxel-based Morphometry (VBM) Preprocessing via Deep Neural Networks},
Year = {2024},
eprint = {arXiv:2408.10656}
}

Outputs 📋

When "Output Modalities" is set to "custom" in the deepmriprep-gui, all output strings are shown:

gui_custom

Most output strings follow the CAT12 naming convention of output files.

Here are descriptions for all output strings:

Input

  • 't1': T1-weighted MR image

Brain Extraction

  • 'mask': Brain mask
  • 'brain': 't1' after brain mask is applied
  • 'tiv_bet': Total intracranial volume in cm³ based on brain extraction

Affine Registration

  • 'affine': Affine matrix moving 'brain' into template space (compatible with F.affine_grid)
  • 'translate', 'rotation', 'zoom', 'shear': Tranformation parameters the affine is composed of
  • 'mask_large': Affine applied to 'mask' with 0.5mm resolution
  • 'brain_large': Affine applied to 'brain' with 0.5mm resolution
  • 'affine_loss': Loss value of the affine registration

Tissue Segmentation

  • 'p0_large': Tissue segmentation map of 'brain_large'
  • 'p0': Tissue segmentation map in 't1' image space (moved 'p0_large')

Tissue Probabilities

  • 'nogm': Small area around the brain stem that is masked in subsequent GM output
  • 'gmv': Gray matter (GM) volume in cm³
  • 'wmv': White matter (WM) ""
  • 'csfv': Cerebrospinal fluid (CSF) ""
  • 'tiv': Total intracranial volume in cm³ based on tissue segmentation (gmv + wmv + csfv)
  • 'rel_gmv': Proportion of GM volume relative to the total intracranial volume
  • 'rel_wmv': Proportion of WM ""
  • 'rel_csfv': Proportion of CSF ""
  • 'p1': GM tissue probability in 't1' image space
  • 'p2': WM ""
  • 'p3': CSF ""
  • 'p1_large': GM tissue probability based on 'p0_large'
  • 'p2_large': WM ""
  • 'p3_large': CSF ""
  • 'p1_affine': GM tissue probability based on 'p0_large' in template resolution
  • 'p2_affine': WM ""
  • 'p3_affine': CSF ""

Nonlinear Registration

  • 'wj_affine': Jacobian determinant of the affine matrix
  • 'warp_xy': Forward warping field (compatible with F.grid_sample)
  • 'warp_yx': Backward warping field (compatible with F.grid_sample)
  • 'warp_mse': Mean squared error between warped p and warp template
  • 'wj_': Jacobian determinant of forward warping field
  • 'v_xy': Forward velocity field (compatible with F.grid_sample)
  • 'v_yx': Backward velocity field (compatible with F.grid_sample)
  • 'wp1': Forward warped 'p1'
  • 'mwp1': Modulated (multiplied with 'wj_'), forward warped 'p1'
  • 's6mwp1': Smoothed with 6mm kernel, modulated (multiplied with 'wj_'), forward warped 'p1'
  • ...analogous for 'wp2', 'mwp2', 's6mwp2', 's8mwp1', ...

Atlases

  • 'aal3': Registered AAL3 atlas in 't1' image space
  • 'anatomy3': Registered Anatomy3 ""
  • 'cobra': Registered Cobra atlas ""
  • 'hammers': Registered Hammers atlas ""
  • 'ibsr': Registered IBSR atlas ""
  • 'julichbrain': Registered Julichbrain atlas ""
  • 'lpba40': Registered LPBA40 atlas ""
  • 'mori': Registered Mori atlas ""
  • 'neuromorphometrics': Registered Neuromorphometrics ""
  • 'suit': Registered SUIT ""
  • 'thalamic_nuclei': Registered Thalamic Nuclei ""
  • 'thalamus': Registered Thalamus ""
  • 'Schaefer2018_100Parcels_17Networks_order': Registered Schaefer 100 ""
  • 'Schaefer2018_200Parcels_17Networks_order': Registered Schaefer 200 ""
  • 'Schaefer2018_400Parcels_17Networks_order': Registered Schaefer 400 ""
  • 'Schaefer2018_600Parcels_17Networks_order': Registered Schaefer 600 ""

For each atlas, there also can be outputted two more modalities:

  • 'aal3_affine': Registered AAL3 atlas in template space
  • 'aal3_volumes': GM, WM and CSF volume in mm³ per region of the AAL3 atlas
  • ...analogous 'anatomy3_affine', 'anatomy3_volumes', 'cobra_affine', 'cobra_volumes' ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepmriprep-0.2.0.tar.gz (17.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deepmriprep-0.2.0-py3-none-any.whl (17.8 MB view details)

Uploaded Python 3

File details

Details for the file deepmriprep-0.2.0.tar.gz.

File metadata

  • Download URL: deepmriprep-0.2.0.tar.gz
  • Upload date:
  • Size: 17.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic

File hashes

Hashes for deepmriprep-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8e6edbfff949997028045eff907074f700c7c5220f60a08599189d8f3e97ed65
MD5 9332d92bd3262de255485080c5b93b3b
BLAKE2b-256 5e822921ad0aabe05770621f55637e89f7c5ca6ad131e0ae5aecbb1aebae4167

See more details on using hashes here.

File details

Details for the file deepmriprep-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: deepmriprep-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic

File hashes

Hashes for deepmriprep-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e25da4dd77fd553701692d166abd1e27fe05e1330e554922dc8b90008db0f11
MD5 0105f60900375ac6ca014e07e9ec537c
BLAKE2b-256 0d802db410113d920ca69b3fd800f445a64f37b3aaca43fe919edad1350e3cdc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page