ECGLight is an end-to-end, compute-light framework and interactive web workstation for converting paper/photographed 12-lead ECG records into high-fidelity 500 Hz digitized signals and performing automated screening for Myocardial Infarction (MI) and Occlusive MI (OMI) pathologies.
π‘ Designed for Low-Resource & Remote Settings: ECGLight runs completely on CPU-only hardware in <30 seconds per ECG without requiring cloud connectivity or expensive GPU infrastructure, democratizing AI-based decision support for clinics worldwide.
- π· High-Fidelity Signal Digitization: Multi-stage computer vision pipeline combining sequential YOLOv11 object detection, scale calibration via Hough lines, K-Means grid construction, and an anti-leakage connected-component filter to extract clean 500 Hz 12-lead signals from smartphone photos or scans.
-
β€οΈ High-Accuracy MI & OMI Screening:
-
95.51% Accuracy (
$F_1 = 0.9519$ ) for MI detection on the benchmark PTB-XL dataset (21,799 ECGs). -
88.89% Accuracy (
$F_1 = 0.8862$ ) for Occlusive MI (OMI) screening on the hospital-acquired ECG-Matrix dataset.
-
95.51% Accuracy (
- β‘ On-Device & Resource-Efficient: Fully functional on standard consumer laptop CPUs or CUDA GPUs.
- π₯οΈ Interactive Web Dashboard Workstation: Streamlit workstation featuring real-time signal viewing, step-by-step digitization previews, R-peak beat segmentation, and downloadable diagnostic prediction tables.
- [2026/07] π Paper released on arXiv: ECGLight: Compute-Light Framework For Paper ECG Digitization and Myocardial Infarction Screening.
- [2026/06] π Open-source release of the ECGLight web dashboard workstation and pre-trained weights repository.
- π Abstract & Key Highlights
- π° News & Updates
- π₯οΈ Web Dashboard Workstation Overview
- π Installation & Setup
- π§ Pre-Trained Classifiers & Tasks
- π Command Line Usage
- π Repository Structure & Directory Organization
- π· How It Works: Signal Digitization
- π How It Works: Signal Analysis & Visualization
- β‘ How It Works: Heartbeat Segmentation
- π§ How It Works: Cardiac Classification
- π€ Collaborating Institutions
- π₯ Authors & Contact
- π Citation
- π License
The ECGLight workstation provides a responsive user interface designed for clinical workflow exploration, research, and education. It unifies the computer vision digitization and diagnostic classification models into a seamless local web application.
-
π· ECG Image Digitizer:
- Upload scanned or photographed ECG images (
.png,.jpg,.jpeg). - Execute the sequential YOLOv11 detection pipeline with real-time visual progress indicators.
- Summarizes detected leads, calibrated sampling rates, and total extracted samples.
- Automatically exports the digitized time-series CSV to
output/digitization/latest_digitized.csv.
- Upload scanned or photographed ECG images (
-
π ECG Signal Viewer:
- Interactive multi-channel ECG signal visualization using native Streamlit/Vega-Lite charts with zoom, pan, and hover tooltips.
- Supports stacked subplots (with distinct clinical lead colorings) and multi-lead overlay modes.
- Computes statistical summaries (mean, SD, min/max, voltage range) and row-level previewing.
-
β€οΈ ECG Classification Engine:
- Evaluates cardiac pathologies using pre-trained time-series ensemble and deep learning classifiers.
- Automatically segments raw signals into heartbeats around R-peaks using the Pan-Tompkins algorithm.
- Inference Mode (Unlabeled Data): Generates downloadable Predictions Tables with predicted class labels and probability confidence scores.
-
Evaluation Mode (Ground-Truth Labeled Data): Displays interactive evaluation metrics (Accuracy,
$F_1$ -Score, Sensitivity, Specificity, Confusion Matrix).
The pipeline operates in four coordinated phases: Digitization $ ightarrow$ Analysis $ ightarrow$ Segmentation $ ightarrow$ Classification. Architectural flowcharts for each phase are provided in the How It Works sections below.
- Python:
3.9+(tested on Python 3.9 and 3.11) - Hardware: Standard CPU (CUDA-capable GPU optional, automatically detected)
-
Clone the Repository:
git clone https://github.com/scai-lab/ECG-Digitization-Classification.git cd ECG-Digitization-Classification -
Create and Activate Conda Environment:
conda env create -f environment.yml conda activate infer
[!IMPORTANT] Windows Compatibility & TensorFlow Setup: If running on Windows and encountering DLL loading errors (
ImportError: DLL load failed while importing _pywrap_tensorflow_internal), install the pinned TensorFlow and Protobuf pairing:pip install tensorflow==2.15.0 protobuf==4.25.3
-
Download Pre-Trained Model Weights: The YOLOv11 detection checkpoints and pre-trained time-series classifiers are hosted on Polybox due to file size constraints:
π Download Pre-Trained Models Directory (ETH ZΓΌrich Polybox)
Extract the downloaded archive and place the
models/directory directly into the root of the project workspace:models/ βββ digitization_models/ β βββ yolo11_full/weights/best.pt β βββ yolo11_lead/weights/best.pt β βββ yolo11_pulse/weights/best.pt β βββ yolo11_patch/weights/best.pt βββ classifier_models/ βββ mi_vs_normal_segmented/ βββ omi_vs_nonomi/ βββ ecg_surgery/ -
Launch the Web Dashboard Workstation:
streamlit run app.py
The classification engine supports three distinct diagnostic tasks using the pre-trained weights in models/classifier_models/:
| Diagnostic Task | Model Architecture | Expected Input Tensor Shape | Test Accuracy | Target Positive Class |
|---|---|---|---|---|
| Normal vs Myocardial Infarction (MI) | Arsenal Ensemble | 12 leads $ imes$ 140 timesteps | 92.3% | MYOCARDIAL_INFARCTION |
| Occlusive MI (OMI) vs Non-OMI | Rocket Classifier | 12 leads $ imes$ 141 timesteps | 88.9% | OMI |
| Pre-Procedural vs Post-Procedural MI | InceptionTime Deep Net | 12 leads $ imes$ 140 timesteps | 91.4% | pre-procedural MI |
- Arsenal: An ensemble of ROCKET classifiers utilizing random convolutional kernels combined with ridge regression feature classification.
- Rocket: Random Omni-directional Kernel Extraction classifier computing high-dimensional time-series representations.
- InceptionTime: A deep 1D convolutional neural network ensemble leveraging multi-scale temporal kernel convolutions.
Process structured directories of paper ECG scans in batch mode:
-
Configure dataset directory paths in
run_org.py:ORGANIZED_DIR = "../ecg_files/ECG_organized_all" # Input dataset root OUTPUT_DIR = "../ecg_files/ECG_digitized" # Destination for CSVs CATEGORIES = ["pre", "index", "post"] # Sub-directories
-
Run the batch digitization script:
python run_org.py
Run standalone inference on pre-digitized CSV datasets:
# 1. Normal vs MI Classification (Arsenal Model)
python archive/classification/run_inference.py --model mi_vs_normal_segmented --input data/ptb_xl/segmented_heartbeats.csv
# 2. Occlusive MI (OMI) vs Non-OMI Classification (Rocket Model)
python archive/classification/run_inference.py --model omi_vs_nonomi --input data/ecg_matrix_omi_segmented_50_150_90.csv
# 3. Custom Output Destination
python archive/classification/run_inference.py --model ecg_surgery --input data/ecg_surgery_segmented_50_150_70.csv --output results/surgery_preds.csv.
βββ app.py # Streamlit application main router
βββ config.py # Centralized configuration and model registry
βββ digitization.py # Core ECGImage extraction pipeline class
βββ environment.yml # Conda environment dependency specification
βββ LICENSE # Non-commercial academic license agreement
βββ README.md # Repository documentation
β
βββ backend/ # Dashboard background execution adapters
β βββ __init__.py # Package initializer
β βββ digitization_runner.py # YOLO loader and single-image processor
β βββ classification_runner.py # Model loader and inference adapter
β
βββ utils/ # Streamlit front-end UI view components
β βββ __init__.py # Package initializer
β βββ branding.py # Header titles and institutional footer logos
β βββ css.py # Custom clinical theme and styling utilities
β βββ hardware.py # Hardware detector (CPU/GPU)
β βββ page_digitizer.py # ECG Digitizer page view
β βββ page_csv_viewer.py # Interactive Signal Viewer page view
β βββ page_classifier.py # Classification workstation page view
β
βββ models/ # Relocated YOLO checkpoints and classifiers (external)
β βββ digitization_models/ # YOLOv11 weights (full, lead, pulse, patch)
β βββ classifier_models/ # Pre-trained classifier weights (Arsenal, Rocket, InceptionTime)
β
βββ archive/ # Archived research, training, and CLI scripts (local)
βββ classification/ # Baseline training and evaluation scripts
The core engine in digitization.py executes a multi-stage computer vision workflow to convert image pixels into calibrated voltage waveforms:
graph TD
A[ECG Image Upload] --> B[Preprocessing: Otsu & Blurring]
B --> C[YOLOv11 Detection & Segmentation]
subgraph YOLOv11 Models
C1[yolo11_full: Lead Boundaries]
C2[yolo11_lead: Text Name Labels]
C3[yolo11_pulse: Calibration Pulses]
C4[yolo11_patch: Waveform Segments]
end
C --> C1 & C2 & C3 & C4
C1 & C2 & C3 & C4 --> D[Hough Lines Calibration]
D --> E[K-Means Row & Column Grid Construction]
E --> F[Anti-Leakage Connected Components Filter]
F --> G[Centroid Trace & Resampling to 500Hz]
G --> H[Export latest_digitized.csv]
- Image Preprocessing: Cleans input scans using shadow removal, Otsu binarization, and Gaussian blurring to separate ink traces from paper texture.
-
YOLO Segmentation: Applies patched YOLO segmentation models across multiple crop scales (
4Γ,4.5Γ,5Γ) to bound individual lead regions. -
Multi-Model Object Detection: Runs YOLO detectors in parallel:
-
yolo11_full: Bounding boxes for the 12 lead channels. -
yolo11_lead: Text label identification (I, II, aVR, V1-V6). -
yolo11_pulse: Bounding boxes for 1 mV calibration reference pulses.
-
- Scale Calibration: Fits Hough lines to calibration pulse boundaries to compute exact voltage scaling ($ ext{V}/ ext{px}$) and time scaling ($ ext{s}/ ext{px}$).
- Grid Construction: Employs K-Means clustering on lead coordinates to construct regular grid layouts (3Γ4, 4Γ3, 6Γ2, 12Γ1) and resolve standard Cabrera lead ordering.
- Contour Tracing & Anti-Leakage Filtering: Traces pixel centroids, baseline-corrects waveforms, and applies an anti-leakage connected-component filter per crop to isolate primary waveform traces from adjacent lead leakage. Signals are resampled to 500 Hz calibrated in mV.
graph TD
A[Upload Digitized CSV] --> B[Parse Lead Voltages & Timestamps]
B --> C[Vega-Lite Interactive Visualizer]
C --> C1[Render Stacked Leads]
C --> C2[Render Overlaid Signals]
B --> D[Compute Signal Statistics: Mean, SD, Min/Max]
D --> E[Display Summary Dataframes & Row Previews]
- Signal Parsing: Validates multi-lead CSV headers, timestamps, and sampling consistency.
- Interactive Rendering: Native Vega-Lite charts enable client-side pan, zoom, and multi-channel hover tooltips.
- Statistical Profiling: Calculates lead-level statistical metrics (mean, standard deviation, voltage range, min/max).
Prepares continuous 12-lead signals for classification models via Pan-Tompkins R-peak detection:
graph TD
A[Digitized 500Hz Signal] --> B[Bandpass Filter 5-15Hz]
B --> C[Derivative Filter]
C --> D[Squaring Operation]
D --> E[Moving Window Integration]
E --> F[Adaptive Thresholding & R-Peak Search]
F --> G[Extract 140-sample Beats: 50ms pre-R, 150ms post-R]
G --> H[Max-Absolute Voltage Normalization]
- Bandpass Filtering: 5β15 Hz bandpass filter isolates QRS energy while suppressing muscle artifact and baseline wander.
- Differentiation & Squaring: Highlights steep QRS slopes and attenuates P/T waves.
- Moving Window Integration: Integrates energy across a 150 ms window to delineate QRS complexes.
- Adaptive Thresholding: Dynamically searches for R-peak maxima.
- Beat Windowing & Normalization: Extracts beat windows centered around R-peaks (50 ms pre-R, 150 ms post-R), normalizes max-absolute voltage, and formats output tensors (140/141 timesteps).
graph TD
A[Segmented Heartbeats] --> B[Numpy3D Reshaping: N_instances Γ 12_leads Γ N_timesteps]
B --> C[Select Classification Task]
subgraph Model Registry
C1[Normal vs MI: Arsenal]
C2[OMI vs non-OMI: Rocket]
C3[Pre vs Post-Procedural MI: InceptionTime]
end
C --> C1 & C2 & C3
C1 & C2 & C3 --> D[Load Pre-Trained Pickled Estimator]
D --> E[Predict Class Labels & Probabilities]
E --> F[Generate Downloadable Predictions CSV]
- Tensor Formatting: Formats heartbeat segments into 3D NumPy arrays
(N_samples, 12_leads, N_timesteps). - Model Evaluation: Invokes the pre-trained pickled estimator for the selected diagnostic endpoint.
- Report Generation: Formats class predictions, confidence probabilities, and diagnostic metrics for export.
This research project was developed in multi-center academic and clinical collaboration:
- ETH ZΓΌrich
- Istituto Cardiocentro Ticino (EOC)
- UniversitΓ della Svizzera italiana (USI)
- UniversitΓ della Campania Luigi Vanvitelli
Β Β Β Β Β Β Β Β
Β Β Β Β Β Β Β Β
Β Β Β Β Β Β Β Β
- Shreyasvi Natraj β snatraj@ethz.ch
- Cyrus Achtari
- Felice Gragnano
- Andrea Milzi
- Marco Valgimigli
- Diego Paez-Granados
If you use ECGLight or its pre-trained models in your research, please cite our arXiv preprint:
@article{natraj2026ecglight,
title={ECGLight: Compute-Light Framework For Paper ECG Digitization and Myocardial Infarction Screening},
author={Natraj, Shreyasvi and Achtari, Cyrus and Gragnano, Felice and Milzi, Andrea and Valgimigli, Marco and Paez-Granados, Diego},
journal={arXiv preprint arXiv:2607.07683},
year={2026},
url={https://arxiv.org/abs/2607.07683},
doi={10.48550/arXiv.2607.07683}
}APA Citation: Natraj, S., Achtari, C., Gragnano, F., Milzi, A., Valgimigli, M., & Paez-Granados, D. (2026). ECGLight: Compute-Light Framework For Paper ECG Digitization and Myocardial Infarction Screening. arXiv preprint arXiv:2607.07683. https://arxiv.org/abs/2607.07683
This repository and model weights are released under the Non-Commercial Academic and Research License Agreement. Please refer to the LICENSE file for full terms. Free for non-profit academic and research use. Commercial use is strictly prohibited.