Skip to content

This repository describes the workflow performed by me during my BSc Biomedical Engineering Thesis

License

Notifications You must be signed in to change notification settings

M-ballabio1/Neuroimaging-Thesis-Project

Repository files navigation

Repository for BSc Biomedical Engineering Thesis

0.Pre-processing and Segmentation

Semi-automatic method for Pre-processing

This folder contain the workflow used for preprocessing T1-W images.

Preprocessing_giusto drawio

Plot histogram subjects (without background)

In this plot, there is a comparison between the different distribution curve of categorical subjects. In particular, we observe a big curve distribution difference in the case of high distorted case. Furthermore, it is interesting to note that in the case of a distorted subject from another category the tissue distribution curve is quite similar to that of a healthy subject.

Untitled Diagram drawio

Why use a thresholding method with manual selection of the thresholds?

Why was it necessary to use a Threshold segmentation method with choice of manual thresholds compared for example to the Otsu segmentation method (automatic thresholds that minimize intra-class variance)? The script multi-otsu creates a segmentation based on Otsu method.

COMPARAZIONE_288618_totale

The comparison between the two segmentation methods highlights a gross segmentation by the automatic segmentation algorithm in the case of subjects with severe brain malformations. This is confirmed by the calculation of the Dice Score metric which reports very low results for the Otsu segmentation, in particular for the recognition of background and CSF.

comparison_method2 drawio

Semi-automatic method for Segmentation

It also contains a .txt file describing the workflow used for tissue segmentation using the ITKSNAP software CLI. In particular, using two different algorithms: Thresholding and Clustering.

segmentation

clustering

Trunk_Cerebellum_Segmentation drawio

1. Segmentation Analysis

This folder contain the script used to exctract segmentation volumes and used to performed statistical test. In particular, two different tests were carried out: ANOVA and T-test

tessuti_tot

anova

t-test3

2.Upload folder

This folder contains two script for the upload and storage of dataset of Benchmark in BrainLife.io The final script used for the upload dataset is written in python and allow to to optimize and speed up the data loading step on the platform.

Upload data drawio(2) drawio

In the following screens, it's possible to see the execution of script to upload the full DBB-dataset. In particular, if the loading is blocked, then by running the script, it restarts from the last point. Foto da Matteo Foto da Matteo (1)

3.Example App for Reproducibility PRE-PROCESSING STEP with Docker container

Input APP

There are two mandatory inputs:

-i, --input         T1-w image to be preprocessed    
-t, --template      template as reference space to be reoriented

and some optional inputs:

-o, --outputdir     if not provided, the scripts create the folder 
-a, --affine        affine matrix to perform rigid transformation to the template
-m, --mask          brain mask to limit Bias-field correction on these voxels     
-n, --nthreads      number of threads

Output APP

The results of app-MBB_preprocessing_t1w are:

 -T1-w reoriented.nii.gz
 -T1-w reoriented_N4BiasField.nii.gz

There are two methods to execute apps:

GUI

-Execute app from GUI on the subjects present in BrainLife project. You can run the BrainLife App DBB_preprocessing_t1w on the brainlife.io platform via the web user interface (UI) or using the brainlife CLI. With both of these two solutions, the inputs and outputs are stored on the brainlife.io platform, under the specified project, and the computations are performed using the brainlife.io cloud computing resources.

EXECUTE_APP_FROM_BL drawio

CLI

-Execute app from CLI using app on all possible subjects. Brainlife CLI could be installed on UNIX/Linux-based system following the instruction reported in https://brainlife.io/docs/cli/install/.

The first time you use the BrainLife CLI on a machine, you need to log in with the brainlife.io credentials

bl login

You can run the App with CLI as follow:

bl app run --id  60cb69e0cdfdb50220fee1c3 --project <project_id> --input t1:<t1_object_id> \
--input mask:<mask_object_id> --input affine:<affine_object_id>

the output is stored in the reference project specified with the id <project_id>. You can retrieve the object_id using the command bl data query, e.g to get the id of the mask file for the subject 0001 :

bl data query --subject 0001 --datatype neuro/mask --project <projectid>

If not present yet, you can upload a new file in a project using bl data upload. For example, in the case of T1-w file, for the subject 0001 you can run:

bl data upload --project <project_id> --subject 0001 --datatype "neuro/anat/t1w" --t1 <full_path>

Running the code locally

You can run the code on your local machine by git cloning this repository. You can choose to run it with dockers, avoiding to install any software except for singularity. Furthermore, you can run the original script using local software installed.

Run the script using the dockers (recommended)

It is possible to run the app locally, using the dockers that embedded all needed software. This is exactly the same way that apps run code on brainlife.io

Inside the cloned directory, create config.json with something like the following content with the fullpaths to your local input files:

{   
    "t1": "./t1.nii.gz",
    "mask": "./mask.nii.gz",
    "affine": "./affine.txt",
}

Launch the app by executing main.

./main

(only two details: install singularity and create a config.json file for path local file).

USING_APP_FROM_CLI drawio

Why is the dual functionality of the DBB Preprocessing t1w app essential in the case of subjects with distorted brain anatomy?

The reason is that the automatic reorientation performed by ANTs is efficient in the case of subjects with healthy brain anatomy. In the case of distorted subjects, the automatic AC-PC alignment is not correct and it is necessary to apply the affine.txt file (obtained manually) for a correct reorientation.

This processed image of pathological subject obtained with automatic reorientation

automatic reorie

This processed image of pathological subject obtained applying affine trasformation file

apply_reorient

The reference template is MNI_152_T1W_brain.nii.gz

TEMPLATE

4.Example script for Comparison Segmentation Masks

This folder contains an example of script for calculate Dice Score between predicted mask and ground truth of each label. The goal is to try to reproduce the comparison step through Dice Score between ground truth masks and predicted masks through the 3D-U-Net convolutional neural network

dice

How does the Dice Score metric work?

Let's take two examples:

  • first SUBJECT ACC (DOWN) with ground truth segmentation mask and 3D-U-Net mask segmentation
  • second SUBJECT HD (UP) ground truth segmentation mask and 3D-U-Net mask segmentation

Dicedrawio

About

This repository describes the workflow performed by me during my BSc Biomedical Engineering Thesis

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published