Skip to content

smcch/Subarachnoid_Hemorrhage_segmentation_and_mortality_prediction

Repository files navigation

Subarachnoid Hemorrhage Automatic Segmentation and Mortality Prediction

This repository contains the Python implementation of the papers:

  • "Mortality Prediction of Patients with Subarachnoid Hemorrhage Using a Deep Learning Model Based on an Initial Brain CT Scan". García-García S, Cepeda S, Müller D, Mosteiro A, Torné R, Agudo S, de la Torre N, Arrese I, Sarabia R. Brain Sciences. 2024; 14(1):10. https://doi.org/10.3390/brainsci14010010
  • "A Fully Automated Pipeline Using Swin Transformers for Deep Learning-Based Blood Segmentation on Head Computed Tomography Scans After Aneurysmal Subarachnoid Hemorrhage". García-García S, Cepeda S, Arrese I, Sarabia R. World Neurosurg. Published online August 5, 2024. https://doi:10.1016/j.wneu.2024.07.216

The repository introduces a streamlined pipeline for:

  1. Automatic Bleeding Segmentation: This segment utilizes the MONAI framework to perform segmentation on non-contrast CT scans from patients diagnosed with subarachnoid hemorrhage.

  2. Mortality Risk Prediction: Predicts the mortality risk within a span of 3 months post-admission using the AUCMEDI framework.

The comprehensive pipeline encompasses DICOM file preprocessing, automatic segmentation using a Vision Transformer (ViT)-based model, mortality prediction through the AUCMEDI model, and the generation of a detailed report. This report includes prediction outcomes, segmentation files, and a volumetric analysis of the bleeding.

imagen

Installation

Download the Miniconda installer:

curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh

Run the installer script:

bash Miniconda3-latest-MacOSX-x86_64.sh

Initialize Miniconda:

source ~/.bash_profile

Create a virtual environment:

conda create --name myenv

Activate the virtual environment:

conda activate myenv

Replace 'myenv' with your desired name.

Clone the repository to your local machine:

git clone https://github.com/your-username/sah-mortality-prediction.git

Navigate to the directory where the repository was cloned.

Install the required dependencies. Make sure you have Python 3.7 or later installed. Use the following command to install the dependencies:

pip install -r requirements.txt

Note: Additional dependencies such as FSL, ANTs, and dcm2niix need to be installed separately and added to the system path. Please follow the instructions below to install them:

Installing External Dependencies

dcm2niix

  1. Visit the dcm2niix repository: https://github.com/rordenlab/dcm2niix
  2. Follow the installation instructions provided in the repository to install dcm2niix.
  3. Add dcm2niix to the system path.

FSL

  1. Visit the FSL installation page: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FslInstallation
  2. Follow the installation instructions provided to install FSL.
  3. Add FSL to the system path.

Usage

For Mac OS users: to avoid error reading .DS_Store files, please enter this command line to delet those files from the input and output directories:

find /path/to/directory -name .DS_Store -type f -delete

replace /path/to/directory with the actual path of the input and output directory.

Command Line Execution for mortality prediction task

Prepare your input data:

Create a directory containing the DICOM files of the SAH patients. Each patient should have a separate subdirectory with their DICOM files. Ensure that the DICOM files contain the necessary information for the prediction (e.g., CT scans).

Run the SAH Mortality Prediction pipeline:

python SAH_mortality_prediction.py -i /path/to/input -o /path/to/output --model 3D.DenseNet121.model.best.loss.hdf5 -g 0

Replace /path/to/input with the path to the directory containing the DICOM files, and /path/to/output with the desired output directory. The --model argument specifies the path to the AUCMEDI model file.

Command Line Execution for automatic segmetation

Setting Up the Pretrained Model:

Begin by downloading the pretrained model for the pipeline.

Click on the link below to access the model:

[Download Pretrained Model] (https://drive.google.com/file/d/1ChgWWranUdj6w3NXXy_RDP2gRQTMNc35/view?usp=sharing)

Ensure you place the downloaded model in the appropriate directory as mentioned in subsequent steps or as required by the pipeline.

Expected Input Format: Ensure your processed non-contrast CT scan in NIfTI format is structured as follows:

input_folder/
└── subject_ID/
    └── subject_ID_ct.nii.gz

Then run the comman:

python inference_2.py --input_dir --output_dir

Graphical User Interface (GUI) Execution

Alternatively, you can use the graphical user interface (GUI) for execution of both tasks (segmentation and mortality prediction). Run the following command:

python gui.py

This will launch the GUI, allowing you to interactively select the input and output directories without specify the AUCMEDI model file.

imagen

View the results:

The pipeline will generate processed NIfTI files and a predictions.csv file in the output directory. Additionally, a report in PDF format will be created for each patient, providing the prediction results, volume slices, and XAI slices. The report files will be named as report_<subject_id>.pdf.

nicaru

imagen

Citations

If you find this pipeline useful for your academic purposes, please include the following citations:

License

Creative Commons Attribution-NonCommercial License: This repository is licensed under the Creative Commons Attribution-NonCommercial (CC BY-NC) license. This license allows others to freely use, modify, and distribute the software for non-commercial purposes only. You are granted the right to use this software for personal, educational, and non-profit projects, but commercial use is not permitted without explicit permission. For more details, please refer to the LICENSE file.

Contact

For any questions or inquiries, please contact:

Santiago Cepeda: [email protected]

About

CNN based mortality prediction after Subarachnoid Hemorrhage (SAH)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages