LeadSeg-ECG: Web-Based 12-Lead ECG Lead Segmentation Using nnU-Net
Authors/Creators
- 1. Department of Mechanical and Aerospace Engineering Politecnico di Torino Torino, Italy
- 2. PolitoBioMed Lab, Department of Mechancial and Aerospace Engineering Politecnico di Torino Torino, Italy
- 3. Department of Research & Development (R&D) GPI SpA Trento, Italy
Description
Title
LeadSeg-ECG: Automatic Lead-Wise Segmentation of 12-Lead ECG Images Using Synthetic Data and nnU-Net
Description
LeadSeg-ECG is a Flask-based research platform for 12-lead electrocardiogram (ECG) image segmentation. The tool allows users to upload ECG images through a browser interface, run semantic segmentation using an nnU-Net v2 model, and visualize the resulting lead masks through multiple outputs, including the original ECG image, raw segmentation mask, colored lead segmentation, segmentation overlay, Grad-CAM style heatmap, and SHAP style attribution map.
The platform is designed for research workflows involving ECG image analysis, model inspection, and visual quality assessment of lead-level segmentation results. It includes a web interface, model inference pipeline, runtime nnU-Net folder preparation, result export utilities, and institution-branded HTML templates. The tool name displayed in the interface is LeadSeg-ECG.
The implemented inference workflow detects the available nnU-Net checkpoint from the project model/ directory, prepares the required nnU-Net runtime structure, converts uploaded ECG images to grayscale before inference, runs prediction on CPU by default, and stores generated visual outputs in the results/ directory. The segmentation display treats class 0 as background and hides it from colored visualizations so that only foreground ECG lead regions are shown. The Grad-CAM style and SHAP style explanation outputs are displayed on white backgrounds with standard color ranges and color bars for interpretation.
This release contains the source code, web templates, static assets, inference utilities, dependency specification, model directory structure, and project documentation needed to run the LeadSeg-ECG platform locally.
Main Features
- Browser-based upload and segmentation of 12-lead ECG images.
- nnU-Net v2 based semantic segmentation workflow.
- Automatic checkpoint detection from the local model/ directory.
- Grayscale conversion before passing images to nnU-Net.
- Colored segmentation visualization with white background.
- Raw mask and overlay visualization.
- Grad-CAM style heatmap visualization with color bar.
- SHAP style attribution visualization with color bar.
- Class 0 background suppression in foreground visualizations.
- Institution-branded interface with M3B Lab and Politecnico di Torino links.
- Local Flask deployment with a Python virtual environment.
Project Contents
The project includes the following main directories and files:
- app.py: Flask application entry point and web routes.
- inference.py: Image preprocessing, nnU-Net inference, fallback demo logic, and visualization generation.
- requirements.txt: Python dependencies required by the project.
- README.md: Complete installation, usage, and troubleshooting documentation.
- templates/: HTML templates for the upload and results pages.
- static/: CSS files and institutional icon assets.
- model/: nnU-Net dataset metadata, plans, and checkpoint files.
- uploads/: Runtime directory for uploaded ECG images.
- results/: Runtime directory for generated segmentation and explanation outputs.
- nnunet_runtime/: Runtime nnU-Net folder structure generated during inference.
Software Environment
The project is intended to run in a Python virtual environment. On Windows, a short-path virtual environment is recommended to avoid long path issues during installation of large packages such as PyTorch:
C:\ecg_flask_venv
The tested environment includes Flask, Pillow, NumPy, PyTorch CPU, SHAP, and nnU-Net v2. Dependencies are listed in requirements.txt.
Running the Platform
After installing dependencies in the virtual environment, the web application can be launched with:
C:\ecg_flask_venv\Scripts\python.exe -m flask --app app run --host 127.0.0.1 --port 5000
The local interface is then available at:
http://127.0.0.1:5000/
DOI
DOI: 10.5281/zenodo.20082175
Suggested Citation
If you use this project, please cite:
Marello, E., Shah, S. T. H., Panagiotopoulos, K., Shah, S. A. H., & Deriu, M. A. (2026). LeadSeg-ECG: Web-Based 12-Lead ECG Lead Segmentation Using nnU-Net. Zenodo. https://doi.org/10.5281/zenodo.20082175.Creators and Contact
For questions, installation issues, model-related problems, or reuse requests, please contact:
Dr. Syed Taimoor Hussain Shah
Politecnico di Torino
Email: taimoor.shah@polito.it
Affiliation and Acknowledgement
This work is developed under M3B Lab, Department of Mechanical and Aerospace Engineering, Politecnico di Torino, Italy.
Keywords
- ECG segmentation
- 12-lead ECG
- Lead segmentation
- nnU-Net
- nnU-Net v2
- Flask
- Biomedical image analysis
- Semantic segmentation
- Explainable AI
- Grad-CAM
- SHAP
- M3B Lab
- Politecnico di Torino
Recommended Zenodo Metadata
Upload type: Software
Publication date: Use the date of the Zenodo release.
Version: Use the project release version assigned by the depositor.
Language: English
Access right: Open Access, if permitted by the associated model and data constraints.
License: Select the intended software license before public redistribution. If no license has been selected yet, the repository should not be assumed to be open-source beyond the permissions explicitly granted by the depositor.
Related identifier:
10.5281/zenodo.20082175
Relation: Is cited by / is supplement to / is new version of, depending on the final Zenodo deposit configuration.
Notes
This software is intended for research and development use. It is not presented as a certified medical device or clinical decision-support system. Users are responsible for validating the model, data, and deployment environment before applying the tool in any scientific, educational, or operational workflow.
Files
LeadSeg-ECG Webapp.zip
Files
(2.0 GB)
| Name | Size | Download all |
|---|---|---|
|
md5:e6ca84da915947f7a5077bda0c39a097
|
2.0 GB | Preview Download |