A deep learning-based medical imaging project for automated brain hemorrhage detection and segmentation using 3D NIfTI CT scans. This project includes a complete pipeline from data preprocessing to an interactive web interface for clinical visualization.
Brain Hemorrhage Segmentation 3D Data is publicly available on Kaggle:
π Download Dataset on Kaggle
The dataset contains 3D CT scan volumes in NIfTI format (.nii.gz) with corresponding hemorrhage segmentation masks for training deep learning models.
- SDG 3 (Good Health and Well-being): This project aims to improve early diagnosis and treatment outcomes for brain hemorrhage patients by assisting radiologists with automated, high-precision segmentation.
- SDG 9 (Industry, Innovation and Infrastructure): We leverage state-of-the-art deep learning architectures like SwinUNETR to foster innovation in medical imaging technology and digital health infrastructure.
- SDG 10 (Reduced Inequalities): By providing an open-source, automated diagnostic tool, we contribute to reducing disparities in healthcare access, potentially aiding regions with limited specialized radiological expertise.
This repository contains:
- Data Processing Scripts - Convert DICOM to NIfTI, preprocessing, visualization
- Model Training - SwinUNETR-based 3D segmentation model
- Interactive Web Interface - Real-time 3D visualization and analysis
- Backend API - FastAPI server for model inference
Brain_Hemorrhage_Segmentation_With_NIFTI/
βββ Brain Hemorrhage Interface/ # Web application
β βββ backend/
β β βββ main.py # FastAPI server
β β βββ best_metric_model.zip # Trained model
β βββ Brain_Hemorrhage_Interface/ # React frontend
β βββ node_modules/
β βββ public/
β βββ src/
β βββ README.md
βββ Scripts/ # SwinUNet Codes
β βββ divide_dicoms.py
β βββ preprocessing_and_visualizing_data.py
β βββ find_dims_and_Swin-Unet_params.py
β βββ dicom_to_nifti.py
β βββ training_with_new_model.py
β βββ find_nobleed_patient.py
β βββ utilities.py
β βββ visualize_testing_data.py
βββ Dataset/
β βββ nifti_files_last_data #Dataset
βββ datasetcard.md # Dataset documentation
βββ modelcard.md # Model documentation
βββ README.md #ReadMe
βββ Testing Area/
β βββ TestDataset.md
β βββ id_0a01....gz
β βββ inference.py
βββ model_results
β βββ metric_test.npy
β βββ metric_train.npy
β βββ loss_test.npy
β βββ loss_train.npy
βββ Consept Note Muhammed Kerem Demirbent.pdf
Architecture: SwinUNETR (Swin Transformer + U-Net)
The trained model (best_metric_model.pth) was extracted from model_results/ and placed in the backend/ directory for deployment. The model is:
- Compressed: FP16 quantization + ZIP compression (244 MB β 74 MB)
- Ready for deployment: Included in this repository
- 3D volumetric segmentation
- Multi-scale feature extraction using Swin Transformer
- Trained on brain CT scans from the Kaggle dataset
- Python 3.10+
- Node.js 18+
- CUDA-capable GPU
- Clone the repository
git clone https://github.com/MuhammedKeremDemirbent/Brain_Hemorrhage_Segmentation_With_NIFTI.git
cd Brain_Hemorrhage_Segmentation_With_NIFTI- Backend Setup
# Navigate to project root (where requirements.txt is located)
# then install dependencies:
pip install -r requirements.txt
# Run the backend
cd "Brain Hemorrhage Interface/backend"
python main.py- Frontend Setup
cd "../Brain_Hemorrhage_Interface"
npm installNote: All frontend dependencies are listed in
package.jsonand will be installed automatically withnpm install.
- Start Backend API
cd "Brain Hemorrhage Interface/backend"
python main.py
# Server runs on http://127.0.0.1:8000- Start Frontend
cd "../Brain_Hemorrhage_Interface"
npm run dev
# Application runs on http://localhost:5173- Open in Browser
Navigate to
http://localhost:5173and upload a NIfTI file (.nii.gz) for analysis.
dicom_to_nifti.py - Convert DICOM files to NIfTI format using dicom2nifti
divide_dicoms.py - Organize and divide DICOM files into patient folders
preprocessing_and_visualizing_data.py - Preprocess CT scans with MONAI transforms and data augmentation
- Includes normalization, resizing, rotation, flipping, and Gaussian noise
- Creates DataLoaders for training
find_dims_and_SWINUNETR_params.py - Analyze dataset dimensions and SwinUNETR model parameters
training_with_new_models.py - Train SwinUNETR model with DiceFocalLoss
visualize_testing_data.py - Visualize training metrics (Dice score & Loss) using matplotlib
utilities.py - Helper functions for training and validation
- 3D Slicer - Used for 3D medical image visualization
- Matplotlib - Used for plotting Dice scores and loss curves
This interface allows clinicians and researchers to upload, analyze, and visualize brain hemorrhage segmentation results in 3D.
The landing page provides a simple drag-and-drop interface or file selection for NIfTI (.nii, .nii.gz) files.
Once the file is uploaded, it is listed in the patient data section. Click the Analyze button to send the data to the deep learning model for processing.
After analysis, the application displays the comprehensive results dashboard:
- 3D Volumetric Render: Interactive 3D view of the brain and detected hemorrhage (red).
- Slice Viewer: Scroll through 2D axial slices.
- Bleeding Detected: Immediate alert with confidence score and voxel volume.
- Tools: Generate Grad-CAM heatmaps, view uncertainty maps, or download the full report as PDF.
Configure application preferences, including theme (Dark/Light), language, and report customization (Hospital Name, Doctor Name).
- 3D Brain Visualization - Interactive Three.js rendering
- Hemorrhage Detection - Real-time segmentation overlay
- Slice Viewer - Browse axial planes
- Grad-CAM Heatmap - Model attention visualization
- Uncertainty Map - Confidence analysis
- Export Reports - PDF generation with results
- Multi-language Support - EN, TR, DE, KO
/predict- Hemorrhage detection with confidence scores/visualize_layers- 3D mesh generation (brain + lesion)/gradcam- Attention heatmap visualization/uncertainty- Uncertainty quantification/get_slice- 2D slice extraction
- Dataset Card - Detailed dataset information
- Model Card - Model architecture and performance metrics
- Concept Note - Project overview
The model file was optimized for GitHub deployment:
| Stage | Size | Compression |
|---|---|---|
| Original (FP32) | 244 MB | - |
| FP16 Quantization | 126 MB | 48% |
| ZIP Compression | 74 MB | 70% total |
The backend automatically extracts and converts the model during runtime.
Please check the dataset license on Kaggle and respect the terms of use for medical imaging data.
Muhammed Kerem Demirbent
- Dataset: Kaggle Profile
- GitHub: MuhammedKeremDemirbent
- MONAI - Medical imaging deep learning framework
- Swin Transformer - Vision transformer architecture
- React Three Fiber - 3D visualization in React
- FastAPI - Modern Python web framework
This software is intended for research and educational purposes only. It is not approved for clinical use or medical decision-making. Always consult qualified healthcare professionals for medical diagnosis and treatment.



