---
title: 'MRPI Project Documentation'
disqus: hackmd
---
MRPI Automatic Software
===
## Table of Contents
[TOC]
## Disclaimer
Copyright 2022 - UNIVERSITY MAGNA GRAECIA OF CATANZARO
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED FOR RESEARCH PURPOSES ONLY, DO NOT USE ANY OUTPUT OF THE SOFTWARE FOR ANY OTHER DIAGNOSTIC AIMS.
## Overview
This manual is intended to help the user to perform the automated measurements of MRPI and MRPI 2.0 indexes.
The GUI (Graphical User Interface) is organized in sections to show each step of the automated measurements.
The proposed automated segmentation approach to calculate the MRPI and MRPI 2.0, developed in MATLAB, is based on the combination of a "revised landmark-based approach" which incorporates information about tissue class, structure, and position, together with a “thresholding-based approach”.
The input data consists of high-resolution (1-mm) volumetric T1-weighted structural MR images. As preprocessing step, the MRI scan must be rigidly registered (using a 6-parameter affine registration) to the standard space (MNI) based on the mutual information metric using the software FSL and resampling the registered T1 using cubic spline interpolation. Then, the volume must be corrected for fluctuations in intensity using the software FREESURFER. To use the software, please follow the instructions about preprocessing. Subsequently, an input matrix in “.mat” must be created to proceed with the automated measurement. Eventually, software fails a manual section is provided to help clinical in obtain a medical report.
# Prerequisites for Deployment
SW_MRPI Executable
1. Prerequisites for Deployment
Verify that version 9.11 (R2021b) of the MATLAB Runtime is installed.
If not, you can run the MATLAB Runtime installer.
To find its location, enter
>>mcrinstaller
at the MATLAB prompt.
NOTE: You will need administrator rights to run the MATLAB Runtime installer.
Alternatively, download and install the Windows version of the MATLAB Runtime for R2021b
from the following link on the MathWorks website:
https://www.mathworks.com/products/compiler/mcr/index.html
For more information about the MATLAB Runtime and the MATLAB Runtime installer, see
"Distribute Applications" in the MATLAB Compiler documentation
in the MathWorks Documentation Center.
2. Files to Deploy and Package
Files to Package for Standalone
================================
-SW_MRPI.exe
-MCRInstaller.exe
Note: if end users are unable to download the MATLAB Runtime using the
instructions in the previous section, include it when building your
component by clicking the "Runtime included in package" link in the
Deployment Tool.
-This readme file
3. Definitions
For information on deployment terminology, go to
https://www.mathworks.com/help and select MATLAB Compiler >
Getting Started > About Application Deployment >
Deployment Product Terms in the MathWorks Documentation
Center.
# Usage
## INPUT PREPROCESSING
The GUI use a matrix preprocessed with [FLS]() and [FREESURFER]() since MR IMAGES need to be rigidly registered using a 6-parameter affine registration to standard space (MNI).
The step are reported below:
1. convert Dicom files to `nii.gz` using [dcm2niix](https://github.com/rordenlab/dcm2niix). For example, the following command try convert all dicom images in `/dicom` and put the output `nii.gz` volume in the folder `/nifti`
```bash
dcm2niix -z Y -x Y -f target_%i -o ./nifti ./dicom
```
Depending on the input volume, `dcm2niix` can output different `nii.gz` files. Select the *cropped* volume that should be named as `target_Crop_1.nii.gz`
2. remove neck and lower head using [FSL robustfov](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FSL) tool (assuming your input volume is INPUT.nii.gz)
```
robustfov --debug -i INPUT -r T1
```
3. then execute [FLS bet](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/BET/UserGuide) for simple brain extraction including the following options
```
bet T1 T1_BRAIN -B -f 0.1 -g 0
```
At this point, your input is ready for the spatial registration.
4. [FSL flirt](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT) registration (two-step process):
```bash
### Brain vs MNI
flirt -in T1_BRAIN.nii.gz \
-ref $FSLDIR/data/standard/MNI152_T1_1mm_brain.nii.gz \
-out T1_BRAIN_reg.nii.gz -omat T1_BRAIN_reg.mat -bins 256 -cost corratio -searchrx -90 90 -searchry - 90 -searchrz -90 90 -dof 6 -interp trilinear
```
```bash
### T1 vs MNI
flirt -in T1.nii.gz -applyxfm -init T1_BRAIN_reg.mat -out T1_reg.nii.gz -paddingsize 0.0 -interp trilinear -ref T1_BRAIN_reg.nii.gz
```
5. Turn `nii.gz` volume in `mgz` format using [Freesurfer mri_convert](https://surfer.nmr.mgh.harvard.edu/fswiki/mri_convert). Let's assume your Freesurfer subject's dir is `$SUBJECTS`, first create a folder for your input (ex: sub1) with the following sub-tree:
```bash
mkdir -p $SUBJECTS/sub1/mri/orig
```
then convert and output your `mgz` by running:
```bash
mri_convert T1_reg.nii.gz $SUBJECTS/sub1/mri/orig/001.mgz
```
6. Run [Freesurfer recon-all](https://surfer.nmr.mgh.harvard.edu/fswiki/recon-all) to perform correction of fluctuations.
```bash
recon-all -s sub1 -motioncor -talairach -nuintensitycor -normalization -no-isrunning
```
7. Turn back `mgz` to `nii`
```bash
mri_convert $SUBJECTS/sub1/mri/T1.mgz T1.nii
```
8. Resample the volume with FSL to 256x256x512 space
```bash
### generating an nifti header
fslcreatehd 512 256 256 1 0.5 1 1 1 0 0 0 2 vf_tmp.nii.gz
### resampling
flirt -in T1.nii -applyxfm -init $FSLDIR/etc/flirtsch/ident.mat -out final.nii -paddingsize 0.0 -interp trilinear -ref vf_tmp.nii.gz`
```
## CREATE INPUT MATLAB
The following script can be used to import a `nii` volume within MATLAB and save it as `.mat` file, so that it is easily reusable without relying on the nifti format anymore.
At the MATLAB prompt enter the following commands:
```matlab=
volume=load_nii(‘final.nii.gz’);
v2=volume.img;
A=permute(v2, [3 2 1]);
B=flipdim(A,1);
C=flipdim(B,2);
volume_finale=C;
save(‘input_matlab’,’volume_finale’)
```
Finally, the matrix saved in `input_matlab.mat` can be user as input for automatic measurements of MRPI and MRPI 2.0 with the Automatic Software
## AUTOMATED MRPI SOFTWARE
1. Open `SW_MRPI` and click on `LOAD SUBJECT`. Choose input_matlab and the scanner field strength (1.5T or 3T).

2. *Automated Measurement of the Third Ventricle and Frontal Horns*:
click on Measure and the gui `segmentazionemanu_ventricoli` will open. Click ok `LOAD IMAGES` `AUTOMATED SELECTION` `AUTOMATED MEASURMENT`, after a couple of seconds the slice where the software perform measures will be showed with the proper value. Close this GUI.

2. *Automated Measurement of Pons and Midbrain*:
Click on `MEASURE` and the gui `pontemensencefalomisura` will open. Click on `PONS AND MIDBRAIN MEASURMENT` and wait to visualize the value in the white boxes. In red is reported the Midbrain value, in green the Pons.

3. *Automated Measurement of Middle Cerebellar Peduncles*:
Click on `Measure` and the GUI `misurapedmedio` will open. Click on `MIDDLE CEREBELLAR PEDUNCLE` and wait. The values measured in different slices are shown. Please consider that a reliable final MCP width value requires at least two measurements on each side.

4. *Automated Measurement of Superior Cerebellar Peduncles*: click on `MEASURE` and the GUI `misurapeduncolosuperiore` will open. Click on `SUPERIOR CEREBELLAR PEDUNCLE` and wait. The values measured in different slices are shown.

**Automated values of MRPI and MRPI 2.0 will be showed at the end of each automated sub-section.**

In case of failure of the automated tool in providing the measurement of a brain structure, it can be manually measured using the gui (on the right side of the interface). The slices can be selected using arrows and the measurement can be performed clicking on the specific commands and then on the selected slices. The manual measurement should be performed in accordance to:
> Quattrone A, Nicoletti G, Messina D, Fera F, Condino F, Pugliese P, Lanza P, Barone P, Morgante L, Zappia M, Aguglia U, Gallo O. MR imaging index for differentiation of progressive supranuclear palsy from Parkinson disease and the Parkinson variant of multiple system atrophy. Radiology. 2008 Jan;246(1):214-21. doi: 10.1148/radiol.2453061703” for midbrain area, pons area, MCP width and SCP width.
> Quattrone A, Morelli M, Nigro S, Quattrone A, Vescio B, Arabia G, Nicoletti G, Nisticò R, Salsone M, Novellino F, Barbagallo G, Le Piane E, Pugliese P, Bosco D, Vaccaro MG, Chiriaco C, Sabatini U, Vescio V, Stanà C, Rocca F, Gullà D, Caracciolo M. A new MR imaging index for differentiation of progressive supranuclear palsy-parkinsonism from Parkinson's disease. Parkinsonism Relat Disord. 2018 Sep;54:3-8. doi: 10.1016/j.parkreldis.2018.07.016.” for the third ventricle width and frontal horns width
## Appendix and FAQ
:::info
**FOR ANY PROBLEM please contact support: mrpiunicz@gmail.com
:::
https://mrpi.unicz.it/