💻 🧠 Brainhack school is taking a break, we'll be back in 2022! 🧠 💻:

Diffusion MRI- From raw data to mapping brain connectomes.

By Michèle W. MacLean
Published on June 12, 2020

"The focus of this project was to combine, use and present a set of tools to organize, preprocess, analyze and visualize diffusion MRI data. The overarching goal is to investigate the consequences of cortical blindness on structural connectivity using diffusion MRI."

Diffusion MRI- From raw data to mapping brain connectomes.

Organizing, preprocessing, analyzing and visualizing diffusion MRI data.

This project is part of the Brainhack Summer School 2020.

Contributors: Michèle W. MacLean & Brainhack School Members


Hello! I'm currently a PhD student in Cognitive Neuroscience at l'Université de Montréal. My main focus is to study cortical visual impairment using MRI techniques. Damage to the primary visual areas can result in clinical blindness and prompt a cascade of dynamical structural and functional alterations of the neural networks at both the cortical and subcortical level. Following this damage, individuals can sometimes preserve the ability to non-consciously process visual information in their blind field, a striking phenomenon know as blindsight. My fascination resides in understanding how the brain can process visual information without conscious awareness.

The overall goal of the current project was to combine, use and present the new tools learned during the BrainHack Summer School to organize, preprocess, analyze and visualize diffusion MRI data acquired at l'Unité de neuroimagerie fonctionnelle during my PhD.

Project definition


This project explored the steps for analyzing diffusion magnetic resonance imaging data starting from the raw data all the way to data visualization. For this, I used previously acquired data from l'Unité de Neuroimagerie Fonctionnelle in Montréal.

Project objectives during BHS 2020: The first steps were to 1) organize the MRI data in a BIDS friendly format and then 2) preprocess the data. Then, I explored 3) analyzing diffusion MRI (i.e. tracking) and 4) performed data visualization.

Overarching goal: The long term goal is to investigate the consequences of a primary visual cortex lesion on structural and functional connectivity using both diffusion MRI and resting state functional connectivity.


This project will rely on the following:

  • GitHub for creating a repository & assembling all the resources.
  • Bash terminal
  • Visual studio code as a code editor
  • BIDS as a standard to organize the neuroimaging data
  • Python
  • Docker container to run preprocessing pipeline and basic tracking
  • DIPY for preprocessing and basic tracking of diffusion MRI
  • Jupyter Notebook and for data visualization
  • Interactive data visualization tools: Nilearn, Plotly, Numpy, Matplotlib, Seaborn, Widgets, etc.


MRI data was acquired with a high resolution 3 Tesla scanner (Siemens Trio system) and consists of a preliminary data set of 5 subjects, including 1 individual with cortical visual impairment with blindsight and 4 neurotypical controls. For each participant, raw structural MRI, resting state functional connectivity, fMRI and diffusion MRI data is avaiblable.

Given the time course of the summer school, after the initial preprocessing of the data, I focused on working with the diffusion MRI data. This data set will allow to first become familiarized with the new neuroimaging tools learned during the BrainHack summer school. When I will acquire a larger data set, during the rest of my PhD, I plan to incorporate it to this project.

The figure above is an example of an individual with cortical visual impairment to give you an idea of the type of data, where A) shows a T1-weighted anatomical scan with three different slice views showing the primary visual cortex removal in the left hemisphere and the destruction of the primary visual areas (V1) and B) the individual's visual field showing a symmetric loss across both eyes leading to a complete contralateral visual loss in the right visual field.

As the dataset is not yet open access, feel free to send me a message if you have any questions and I'll be happy to answer!


For the project:

  • The current markdown document, completed and revised.
  • Organization of MRI data into BIDS format
  • The diffusion MRI data preprocessed.
  • Basic tracking performed on the preprocessed diffusion MRI data with an output of streamlines & connectivity matrices.
  • Data visualization within a jupyter notebook using plotly, nilearn and matplotlib.
  • Requirements.txt for the Jupyter notebook

For the course:


  1. Data Organization/Management.
  • Convert dicoms to a BIDS friendly dataset. This tutorial served as a guideline.
  1. Preprocessing diffusion MRI data.
  1. Creating a seed mask.
  1. Tracking of diffusion weighted images (DWI)
  1. Data visualization
  • Data visualization was performed within a Jupyter notebook using Plotly, Nilearn, Matplotlib, Seaborn and more (see visualization examples with gif below).

Progress & Results

Data visualization

  1. Connectivity matrix
  2. Connectome projected on 3 views of a 2D glass brain
  3. Connectome projected on a 3D glass brain
  • The jupyter notebook version of all three figures is interactive with a drop-down for each subject using widgets.
  • The connectivity matrices (.mat files) used for the data visualization can be found here
  • The figures (saved as .png or .html) for each subject can also be found here

Progress overview

This project was initiated by Michèle MacLean May 19th 2020 as part of the BrainHack Summer School 2020. Organization of MRI data into BIDS format, preprocessing and basic tracking of the data is complete as well as data visualization for the deliverable for week 3. See the methods section for a detailed description. This will be an ongoing project that I will continue to work on after BrainHack Summer School. Feedback is welcome!

Tools and skills I learned during this project

  • Bash terminal
  • GitHub
  • Markdown
  • Visual Studio Code
  • How to implement BIDS
  • Python scripts
  • Docker container
  • DIPY for preprocessing and basic tracking of diffusion MRI
  • Jupyter Notebook
  • Interactive figures in Jupyter Notebook using data visualization libraries: Nilearn, plotly & matplotlib, etc.
  • Preprocessing diffusion MRI data
  • Tracking diffusion MRI data
  • Mapping connectomes


The BrainHack Summer School 2020 provided a theoretical framework as well as an extensive set of practical neural data analysis and visualization tools that were mainly all new to me. For the current project, my goal was to maximize using these new tools, to learn and apply the open science protocols in order to analyze data within my own doctoral project. Within the time frame of the summer school, I set out to perform all the steps starting from raw diffusion MRI data, which I previously acquired at l'Unité de neuroimagerie fonctionnelle, leading to data visualization. In particular, this dataset was organized into a BIDS friendly format, preprocessed with a python script within a docker container, basic tracking was also performed using another python script within a second container and finally data visualization was done using multiple librairies within a jupyter notebook. As a neuroscientist with a limited previous background in programming, I believe I sensibly improved my skills towards performing independently the whole process to analyze neuroimaging data. As I plan to continue working on this project with the new tools learned, my next immediate step will be to increase the number of subjects. Also, my next challenge will be to specifically account for brain injuries leading to cortical visual impairment during the analyses as this requires additional algorithmic tools and modifications to the preprocessing and analysis pipelines.


Thanks to the wonderful BrainHack Summer School 2020 for this experience as well as all the excellent ressources provided! I would like to thank my instructors Noor and Benjamin for their advice and for providing specific ressources for this project. Special thanks to my instructor Greg who originally developed the python scripts and docker images I used and invested a lot of time to help and contribute to this project. I would also like to thank my new friend and coding partner Daniel and my friend Simon who was a great study buddy throughout the summer school!

Be sure to check out the other cool projects from the BrainHack Summer School 2020 here!


  1. Abraham, A., Pedregosa1, F., Eickenberg1, M., Gervais, P., Mueller, A., Kossaifi, J., Gramfort, A., Thirion, B., Varoquaux, G. (2014). Machine learning for neuroimaging with scikit-learn. Frontiers in Neuroinformatics 8: 14. https://doi.org/10.3389/fninf.2014.00014 (for using nilearn)
  2. Garyfallidis E, Brett M, Amirbekian B, Rokem A, van der Walt S, Descoteaux M, Nimmo-Smith I and Dipy Contributors (2014). DIPY, a library for the analysis of diffusion MRI data. Frontiers in Neuroinformatics, vol.8, no.8.
  3. Gorgolewski, K.J., Auer, T., Calhoun, V.D., Craddock, R.C., Das, S., Duff, E.P., Flandin, G., Ghosh, S.S., Glatard, T., Halchenko, Y.O., Handwerker, D.A., Hanke, M., Keator, D., Li, X., Michael, Z., Maumet, C., Nichols, B.N., Nichols, T.E., Pellman, J., Poline, J.-B., Rokem, A., Schaefer, G., Sochat, V., Triplett, W., Turner, J.A., Varoquaux, G., Poldrack, R.A., 2016. The brain imaging data structure, a format for organizing and describing outputs of neuroimaging experiments. Sci Data 3, 160044.
  4. Kiar, G. <gkiar.github.io>. (2020). Dipy Tracking and Connectome Generation (Version v0.4.0). Zenodo. http://doi.org/10.5281/zenodo.3699595
  5. Kiar, G. (2020). dipy. Retrieved from https://github.com/gkiar/stability/tree/master/code/tractography/dipy Kiar, G. (2019). Using FSL from FMRIB at Oxford- BIDS App - FSL Diffusion Preprocessing (Version 5.0.9). Zenodo. http://doi.org/10.5281/zenodo.2566455
  6. Kiar, G. (2019). preprocessing. Retrieved from https://github.com/gkiar/stability/tree/master/code/preprocessing
  7. Kiar, G. (2019). mask2boundary. Retrieved from https://github.com/gkiar/mask2boundary
  8. Klein, A. and J. Tourville (2012). 101 labeled brain images and a consistent human cortical labeling protocol. Frontiers in Neuroscience 6: 171.https://doi.org/10.3389/fnins.2012.00171

See also these similar projects

Does rs-fMRI preprocessing matter for prediction performance in machine learning?

Machine learning models are often used to analyze fMRI data, whether it be a simple classification or regression problem or something more complex. …

Discover this project

Combine EEG/MRI/Behavioral data-sets to learn more about Music/Auditory system

In this project I aim to combine data from different modalities (fMRI, EEG, and behavioral) to understand more about sound and music processing. My …

Discover this project