Diffusion MRI reconstruction Project

By Erjun Zhang, & Brainhack School 2020
Published on May 16, 2020

"This project is about diffusion magnetic resonance (MR) data processing and analysis. It mainly consists of three parts: brain diffusion MR data preprocessing, diffusion MRI images reconstruction, data visualization and left and right hemispherical preprocessed MR images classification. The whole procedures can be found in this Jupyter Notebook file. Explanations about procedures results and other details are given in it. With reproducibility being a primary concern, this project was completed by using open-source software/tools (Python, FSL, DIPYPE…) and dataset (dHCP and PRIME)."

Project definition


Low blood sugar is a common problem in both children and adults. Existing research showed that it may lead to serious both transient and permanent structural abnormalities on brains. Magnetic resonance imaging (MRI), specially diffusion MRI, has a higher in vivo sensitivity to lesions in soft tissues compared to other imaging modalities, and has potential to identify and quantify brain structure changes. Some of these changes are not appraient enough,even for experienced experts. Machine learning is a useful method to discover potential features.

Currently, there are some open-source software to reconstruct and analyze diffusion MRI data. However, only using these tools, one, like me as a new student in this field, may get confused about operations and principle behind them. This seriously stops people to reach their long-term goals in their diffusion MRI project.

Thus, I began this project to preprocess dMRI data, reconstruct diffusion MR images and do some analysis by using machine learning. The goals are as following:

  • Get preprocessed diffusion MR images from raw data;
  • Reconstruct diffusion tensor images from the preprocessed data;
  • By using machine learning, try to classify two hemispherical brains from preprocessed diffusion images.


The “Diffusion MRI reconstruction project” will rely on the following tools:

  • Python3: coding language used to complete this project (Python2 also needed for some special packages).
  • Github and git: to organize this project and make version control
  • Jupyter Notebook: to file code, visualizations and results
  • Markdown, to structure the text in README and Jupyter Notebook
  • Visual Studio Code: to be code editor
  • Nipype: to use FSL command preprocessing image data
  • DIPY: to be used as diffusion tensor imaging (DTI) fitting and denoising
  • matplotlib, plotly and ipython widgets: data visualization
  • Linux (Ubuntu 20.04)


This project used data from online dataset offered by:

  1. The Developing Human Connectome Project. It consists of over 800 neonatal scans and over 250 fetal scans and can be used for data analysis after image reconstruction.
  2. PRIME: used this dataset to reconstruct diffusion Images. This also can be downloaded here directly.
  3. Since during preprocessing, we used epi data with two opposite phase-encoding directions to correct distortions, other data can also be used as the source data if it meets this requirement.
  4. Data used for analysis is generated from image data after preprocessing. The final data can be found in this github project folder.


At the end of this project, we will have: Jupyter notebook will be developed, allowing diffusion MR reconstruction and data analyzation. Weekly Deliverables are as following:


Progress overview

Since May 11, this project goes well and three goals of this project have been reached. This is just to let me be familiar with steps and tools of diffusion MRI processing. Next, I will combine different processing methods into this project. Specifically, I would like to look deep into DTI model fitting and try to replace it by a new model created by myself.

Tools I learned during this project

  1. Python
    • FSL, Nipype.interfaces, DIPY
    • matplotlib, plotly, ipywidgets
    • Function definition and calling
  2. Markdown
    • Format this README file
    • Insert figures and animation
    • LaTex to edit mathematical equations
  3. Github
    • Version control
    • Project organization
  4. BIDS
  5. Jupter notebook
  6. Found and learnt to use some small but useful tools
    • Peek for GIF making
    • Gedit to edit code or markdown
  7. Medical file format (NII) and data structure (BIDS)
  8. Statistical method and machine learning


Data Visualization (see gif figure below):

  • 3D volume slices image
  • Interactive widgets use to show preprocess results
  • Interactive widgets use to show reconstruction results

Preprocessing results


DTI results


Left and right hemispheres classification results


Conclusion and acknowledgement

This project started with medical imaging data format, then preprocessed the diffusion weighted images, which includes MP-PCA denoising, FSL TOPUP distortion correction and head movement correction. After this, DTI images were reconstructed from these preprocessed images successfully. Additionally, a dataset for left and right hemispheres classification was generated from these preprocessed images. By using the KNN method, classification accuracy of 92% was reached. As a starter, I will continue this project in the future. Soon, self-made models, instead of DTI model, will be used to reconstruct diffusion images. After that, I would like to use machine learning methods to classify potential changes of brain microstructures.

Thanks to Brainhack Summer School 2020 and all instructors. Specifically, I would like to thank my instructors Noor, Greg and Agah for your advice, instruction and encouragement. I feel so lucky to find and take this summer school. During this short one month, I touched so many new skills and tools and began my first neuroscience project. I would also like to thank all the summer school students, just because of you, I know how wonderful the neuroscience world is and how active the neuroscience group is!

See also these similar projects

Can we identify sex using fMRI?

Does functional connectivity between brain regions differ in male and female? If yes then fMRI data can be used to distinguish sex on the basis of the …

Discover this project