To use this project, follow these steps:
- Clone the Repository:
git clone https://github.com/eyalhana/SSPCMC-T1.git
- Install Dependecies
We use three different enviroments. one for nnunet, one for segmentation processing and one for sspcmc (the network).
conda env create -f environment_nnunet.yml conda env create -f environment_seg_process.yml conda env create -f environment_sspcmc.yml
Our approach based on using pretrained nnUNet for extracting segmentations on inference time. It is possible to use either the pretrained models or train nnUNet from scrach following nnUNet GitHUB.
Before using our network. the data should be aranging as following:
data/
├── cardiac_STONE_dataset/
│ └── seperate_cases/
│ ├── data/
│ ├── data_nii_gz/
│ ├── norm/
│ ├── prob/
│ ├── prob_bg/
│ ├── seg/
│ ├── seg_info/
│ ├── seg_nii_gz/
│ ├── seg_blood/
│ ├── seg_fullbody/
│ ├── seg_gt/
│ └── trigger_time/
The directories include:
- data - one npy file for each slice (so for example, if the size of the slice is 160x160 and there are 11 timepoints, the dims will be 160x160x11)
- norm - the normelize parameters of each slice.
- prob - the softmax output of the nnUNet of the cardiac - the probability of correctness of the segmenation
- prob_bg - the softmax output of the nnUNet of the background - the probability of correctness of the segmenation
- seg - the cardiac segmenation
- seg_blood - blood pool segmentaion
- seg_fullbody - blood pool + cardiac segmentation
- seg_gt - the ground true cardiac segmenation (if known)
- trigger_time - the trigger time vector
- seg_info - include data on the choosen reference slice and the valid segmentations.
So for example, if we have a scan from the Technion MRI.
We could use/adjust the following script in order to create data, trigger_time, norm and data_nii_gz dirs and files.
conda activate sspcmc
utils/create_technion_db.py
Than we could use utils/inference_nnunet.sh to generate seg, seg_blood, seg_fullbody, prob, prob_bg dirs. this script run nnunet on the saved pretrained models that located in /home/eyalhan/nnUNetT1/nnUNet_results/Dataset510_Testsplits_cardiac/nnUNetTrainer__nnUNetPlans__2d/ (5 checkpoints for each fold) and doing some processing on the segmentations and divide the outputs to dirs and seperate files for each slice.
In tcml servers the processed dirs of the inner dataset (MOLLI dataset that acquired in the Technion) which include 19 scaned cases are in /tcmldrive/Eyal/PCMC-T1-24/PCMC-T1-24/data/TechnionDB_1404_v2 f
The dataset preprocess is unique for this specific dataset since it include ground truth segmentations and it in .mat format.
We utilized a publicly available myocardial T1 mapping dataset. To use this dataset, please download it in '.mat' format:
Use wget (Linux/macOS) or curl (Windows/Linux/macOS) to download the file:
- On Linux/macOS, use
wget:wget -O data/T1Dataset210.mat [https://dataverse.harvard.edu/api/access/datafile/43188520](https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/DHEUAV/H5WVDS) - On Windows/Linux/macOS, use
curl:curl -o data/T1Dataset210.mat [https://dataverse.harvard.edu/api/access/datafile/43188520](https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/DHEUAV/H5WVDS)
and it located on TCML servers on /tcmldrive/Eyal/PCMC-T1/data/T1Dataset210.mat
The dataset was preprocessd using src/data_preprocessing.py and the same scripts as in the Technion dataset description
The preprocessed npy files full_norm_matrix.npy full_set_data.npy full_set_segmentation.npy full_set_trigger_time.npy located in /tcmldrive/Eyal/PCMC-T1/data
After preprocess the files we should extract segmentations and seperated the slices to the dirs.
We could use/adjust the scripts of the Technion-dataset.
The final seperated files and dirs are located in:
/tcmldrive/Eyal/PCMC-T1-24/PCMC-T1-24/data/cardiac_210/seperate_cases for the public STONE dataset
once we have those dirs and files we could start use our network after choosing the correct config file at line 35 in scripts/solver.py (#TODO - add to args). the relevant options are solver_210_data.yaml for STONE dataset and solver_Technion_data.yaml for the Technion dataset)
The paths to the datasets folder should be updated in /src/data_loaders.py #TODO - update it in the config file only.
The following shell file, run scripts/solver.py over all the dataset.
It is needed to update log paths in the shell file and the output path in the config. #TODO - make everything in the config file. (It is needed to comment/uncomment the sections in the shell file depanding on the required dataset)
conda activate sspcmc
./scripts/run_solver.shThe output results will be saved at the results path the shown in the config file.
The important output files:
- y_trigger_time.npy - times vector
- original_T1.png/npy - the original T1 map
- 1_registered_images.png/npy
- maps_model.npy - matrix in dim of [W,H,2]. the first slice is the R2 map and the second is the registerd T1 map
- the registered T1 map appear also in 1_registered_images.png/npy
running example to STONE 210 dataset (after updating the desired config file in line 35)
python scripts/solver.py --patient 23 --slice 1