Method Article

Automated 12-Lead Electrocardiograms (ECG) Digitization and WaveForm DataBase (WFDB) Standardization: Insights from Vietnamese Clinical Data

DOI:

10.3791/70359

March 13th, 2026

In This Article

Summary

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

Here, we present a reproducible protocol for converting 12-lead ECG images from real-world clinical reports into calibrated, WFDB-compliant digital signals for standardized downstream analysis, integrating grid calibration, YOLOv12-based lead localization, waveform extraction (Viterbi or improved centerline), and visual validation checkpoints.

Abstract

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

Many clinics still archive 12-lead electrocardiograms (ECGs) as printed paper records or raster images embedded in PDF reports, which limits interoperability and downstream computational analysis. Here, we present a reproducible digitization protocol that converts ECG report images into WaveForm DataBase (WFDB)-compliant digital signals for standardized downstream use. The protocol consists of (i) grid detection and pixel-to-physical calibration, (ii) automated localization and labeling of the 12 lead regions using an object detection model, (iii) signal preprocessing and normalization, and (iv) waveform extraction using either a continuity-constrained path method (Viterbi) or an improved centerline-based approach. The workflow is designed to handle heterogeneous clinical layouts, variable grid visibility, and common imaging artifacts, and includes visual checkpoints for quality control at each stage. The protocol outputs time-aligned 12-lead WFDB records suitable for reproducible analysis in signal processing and machine-learning pipelines.

Introduction

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

The 12-lead electrocardiogram (ECG) is a cornerstone of cardiovascular assessment and remains widely used for screening, monitoring, and clinical decision-making1. Despite ongoing digitization efforts, many institutions still store ECGs as printed paper records or rasterized images embedded in PDF reports, which reduces searchability and complicates longitudinal follow-up2. Importantly, image-based storage prevents direct use of standardized ECG toolkits and machine-learning pipelines that require calibrated time-series signals rather than images3. The overall goal of this protocol is to provide a reproducible and standardized method for converting electrocardiogram images into calibrated digital signals suitable for downstream computational analysis.

Automated ECG digitization seeks to reconstruct voltage–time signals from scanned ECG images4. However, real-world clinical ECG scans often present heterogeneous report layouts, variable grid visibility, compression artifacts, non-uniform illumination, and additional markings such as stamps or annotations5. These factors can degrade lead localization and waveform tracing, limiting reproducibility across institutions and device vendors6. Therefore, a practical digitization workflow should provide robust grid calibration, reliable lead separation and labeling, and standardized export to a widely adopted signal format such as WFDB7. Standardized digital formats improve interoperability across institutions and facilitate reproducible analysis using established electrocardiogram signal-processing libraries.

Several ECG digitization tools have been proposed (Table 1), yet clinical deployment remains challenging because performance can be sensitive to scan quality and layout variability8,9,10. Recent studies have also explored automatic lead extraction from ECG paper records using deep learning, further highlighting the need for robust parsing under diverse layouts and artifacts11. Related digitization software has also been introduced to improve robustness under heterogeneous clinical conditions12. In parallel, open toolkits and resources for ECG-image research have been introduced to facilitate method development and benchmarking13. Unlike existing digitization tools that may be sensitive to layout variability or limited to specific scan formats, this protocol integrates grid calibration, automated lead localization, and standardized WFDB export to improve robustness across heterogeneous clinical reports. In this work, we focus on an end-to-end pipeline that targets real-world ECG PDFs and scanned records, emphasizes reproducibility, and outputs WFDB-compliant multi-lead signals for downstream analysis.

We propose a fully automated and reproducible protocol for converting 12-lead ECG report images into WFDB-compliant digital signals. The protocol integrates (i) grid-based pixel-to-physical calibration using standard ECG settings (25 mm·s-1, 10 mm·mV-1), (ii) YOLOv12-based localization of both lead regions and lead icons to support robust lead identification in heterogeneous report layouts, and (iii) two alternative waveform extraction procedures, including an improved centerline method designed to improve trace continuity under variable line thickness and small discontinuities. These components are aligned with prior work on signal extraction, robust digitization software, and practical digitization strategies under heterogeneous clinical conditions14. The resulting WFDB records enable downstream analysis using standard ECG toolchains. This protocol is particularly suitable for retrospective digitization of archived electrocardiogram reports stored as scanned paper records or rasterized PDFs and may require adaptation when grid lines are absent or severely distorted.

Access restricted. Please log in or start a trial to view this content.

Protocol

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

Obtain Ethics Committee (Institutional Review Board) approval from Tam Duc Hospital (Protocol ID: 24751791) prior to retrospective data collection. De-identify all ECG reports before analysis by removing direct identifiers (e.g., patient name, medical record number, date of birth, and visit date) and replacing them with a non-identifying study ID. Use only de-identified ECG data for model development and evaluation.

1. Prepare materials, software, and inputs

  1. Clone the project repository and verify the directory structure, including baselines/, core_binary/, data/, evaluation/, outputs/, public/, results/, weight/, and wrapper/, along with README.md and requirements.txt (see Data Availability).
    1. Create (or verify) runtime subfolders under data/ and outputs/, including data/raw_pdf/, data/raw_scans/, outputs/images/, outputs/preprocessed/, outputs/calibrated/, outputs/yolo_boxes/, outputs/lead_crops/, outputs/masks/, outputs/traces/, outputs/signals_csv/, and outputs/wfdb/.
  2. Install required software dependencies (Python, OpenCV, NumPy/SciPy, PyTorch, Ultralytics (YOLOv12 training/inference framework) /YOLO, and WFDB) and document versions in the materials list (see Table of Materials).
  3. Place ECG inputs into data/raw_pdf/ (PDF reports) or data/raw_scans/ (paper scans).
  4. Scan paper ECGs in grayscale at 300 dpi and keep the page flat to avoid perspective distortion (see Table of Materials).
    NOTE: Use the paper speed and gain reported on the ECG printout when available (e.g., 25 mm·s⁻1, 10 mm·mV⁻1), consistent with the calibration stage in the overall workflow (see Figure 1).

2. Convert ECG PDFs to images

  1. Convert each ECG PDF page to a grayscale image at 300 dpi.
  2. Save each page as .png (preferred) or .tiff using minimal compression to preserve gridlines and waveform details.
  3. Store exported images in outputs/images/ and keep filenames consistent across all pipeline stages (see Figure 2 for a representative input layout).

3. Preprocess ECG images (contrast and noise)

  1. Apply CLAHE to enhance faint gridlines and waveform contrast.
  2. Apply a light Gaussian blur to reduce high-frequency noise while preserving waveform edges.
  3. Crop large black margins while preserving the full ECG content area.
  4. Rotate the image to an upright orientation if the scan/export is rotated.
  5. Save preprocessed outputs to outputs/preprocessed/.
  6. Visually inspect a subset of outputs and confirm that gridlines and traces remain readable (see Figure 2).
    CAUTION: Avoid aggressive smoothing that breaks thin waveform segments.

4. Detect grid spacing and calibrate scale (pixel → mm)

  1. Detect grid spacing using Hough line detection for vertical/horizontal gridlines.
  2. Estimate the mean distance between adjacent gridlines (pixels) and store the grid spacing value.
  3. If Hough line detection fails, estimate spacing using Fourier analysis of row/column projections.
  4. If Fourier analysis fails for dotted grids, estimate spacing using Hough circle detection (or dot periodicity).
  5. If all grid detectors fail, set a fallback spacing value (e.g., 59 pixel) and flag the record for review.
  6. Compute the pixel-to-mm conversion using the detected spacing and the ECG paper standard (e.g., 25 mm·s⁻1 and 10 mm·mV⁻1; see Figure 1).
  7. Rescale the image using bicubic interpolation to normalize scale across records.
  8. Save calibrated images to outputs/calibrated/ and store calibration logs per record.
    NOTE: Refer to Supplementary File 1 (Algorithm 1) for implementation-oriented pseudocode of grid spacing detection and pixel-to-physical calibration.

5. Localize 12-lead regions using YOLOv12

  1. Load the trained YOLOv12 model for lead-region detection (see Table 2 for training parameters).
    1. Use the YOLOv12 training/inference framework implementation without architectural modifications to detect and separate the 12 lead regions in each ECG image for downstream digitization (see Figure 1).
  2. Run inference on each calibrated image using the configured inference size (e.g., imgsz = 1024).
  3. Apply non-maximum suppression and keep the highest-confidence bounding box per lead class.
  4. Export bounding boxes to outputs/yolo_boxes/ in a reproducible format (TXT/CSV/JSON).
  5. Save overlay images showing predicted lead-region boxes and labels for verification (see Figure 3 and Figure 4).
  6. Flag records with missing leads, duplicated leads, or inconsistent layout and exclude them from automatic export if needed.
    NOTE: Refer to Supplementary File 1 (Algorithm 2) for pseudocode of YOLOv12-based lead region extraction and box post-processing.

6. Localize lead icons using YOLOv12

  1. Load the trained YOLOv12 model for lead-icon detection (see Table 2 for training parameters).
    1. Use the same YOLOv12 training/inference framework implementation without architectural modifications to detect lead icons for robust lead identification in heterogeneous layouts (see Figure 1).
  2. Run inference on each calibrated image using the configured inference size and thresholds reported in the main text.
  3. Apply non-maximum suppression and keep the highest-confidence bounding box per lead-icon class.
  4. Export lead-icon bounding boxes to outputs/yolo_boxes/ in a reproducible format (TXT/CSV/JSON).
  5. Save overlay images showing predicted lead-icon boxes and class labels for verification (see Figure 5 and Figure 6).
  6. Evaluate lead-icon detection performance and report quantitative results and metric definitions (see Table 5 and Table 6).
  7. Compare lead-region detection and lead-icon detection under the same evaluation protocol and runtime reporting convention.

7. Crop each lead region and standardize crops

  1. Crop each lead region from the calibrated image using the predicted bounding box coordinates.
  2. Pad crops to a consistent size when lead regions vary across layouts.
  3. Save cropped images to outputs/lead_crops/ using the naming scheme: recordID_leadName.png.
  4. Confirm that all 12 leads are present for each record before waveform extraction (see Table 3 and Table 4).

8. Generate a binary signal mask for each lead crop

  1. Normalize each lead crop intensity to an 8-bit intensity range.
  2. Apply adaptive thresholding (or Otsu thresholding) to separate the waveform trace from background/gridlines.
  3. Apply morphological cleanup (e.g., opening/closing) to suppress residual grid artifacts.
  4. Bridge small gaps in the trace using interpolation or connectivity-based filling.
  5. Save the final binary mask to outputs/masks/ and verify mask quality on representative samples (see Figure 7).
    NOTE: Refer to Supplementary File 1 (Algorithm 3) for lead-region mask generation details when using bounding-box-guided masking.

9. Extract waveform traces (choose either Viterbi-based path extraction or improved centerline extraction.

  1. Extracting waveform traces using Viterbi-based path extraction
    1. Compute a cost map on the binary mask that penalizes discontinuities and favors trace-like pixels.
    2. Run Viterbi decoding to obtain a continuity-constrained path across the lead crop.
    3. Smooth the extracted path and interpolate missing segments when necessary.
    4. Save path coordinates to outputs/traces/ and save overlay plots for validation (see Figure 8).
      ​NOTE: Refer to Supplementary File 2 (Algorithm 4) for Viterbi-based waveform extraction and visualization pseudocode.
  2. Extracting waveform trace using Improved centerline extraction
    1. Skeletonize the binary mask to obtain a centerline candidate.
    2. Remove spurious branches and isolated components caused by grid noise.
    3. Smooth the centerline and enforce left-to-right continuity.
    4. Interpolate short missing segments to preserve waveform continuity.
    5. Tune dataset-specific parameters (e.g., binarization thresholds, morphological kernel sizes, pruning length, smoothing strength, and gap-interpolation limits) to optimize centerline continuity under the imaging conditions of the study dataset.
    6. Save centerline coordinates to outputs/traces/ and save overlay plots for validation (see Figure 9).
      ​NOTE: Use a standard skeletonization-based centerline principle and improve robustness via dataset-specific parameter tuning and post-processing; refer to Supplementary File 2 (Algorithm 5) for centerline extraction, smoothing/interpolation, parameter settings, and storage pseudocode.

10. Convert pixel traces to calibrated signals (mV vs time)

  1. Convert pixel y-coordinates into voltage using the calibrated grid scale (10 mm·mV⁻1) and pixel-to-mm mapping.
  2. Convert pixel x-coordinates into time using the calibrated grid scale (25 mm·s⁻1) and pixel-to-mm mapping.
  3. Resample each lead to a fixed sampling rate (e.g., 100 Hz) and align all 12 leads in time.
  4. Save the 12-lead signals as CSV files in outputs/signals_csv/ with consistent column names and units.

11. Export WFDB records and validate outputs

  1. Convert each 12-lead CSV into a WFDB record using the WFDB library.
  2. Write the .hea header file containing record name, sampling rate, signal gains, baselines, and lead names.
  3. Write the .dat signal file using a consistent numeric type (e.g., 16-bit) and unit convention (e.g., µV).
  4. Reload each WFDB record and plot all 12 leads to confirm lead order, naming, and time alignment (see Figure 10).
  5. Save final WFDB outputs to outputs/wfdb/ and save validation plots.
    NOTE: Refer to Supplementary File 3 (Algorithm 7) for CSV-to-WFDB conversion details and optional annotation writing when metadata are available.

12. Checkpoints and troubleshooting

  1. Reject or flag any record with unreliable grid calibration, missing leads, or severe occlusions.
  2. Re-run preprocessing and calibration with adjusted parameters for flagged records.
  3. Re-run detection with updated confidence/IoU thresholds when leads are missed.
  4. Summarize failure modes and exclusion criteria in a results table.

Access restricted. Please log in or start a trial to view this content.

Results

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

Input preparation
ECG reports were successfully converted from PDFs or scans into standardized, axis-aligned images suitable for downstream processing. For paper ECGs, scans were acquired at 300 dpi in grayscale and saved as PNG/TIFF to reduce compression artifacts. The most common input issues were (i) excessive compression from PDF exports, (ii) partial cropping that removed lead regions or labels, and (iii) perspective distortion in smartphone photographs. Records affected by cropping or severe di...

Access restricted. Please log in or start a trial to view this content.

Discussion

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

This study presents an automated end-to-end pipeline that converts 12-lead ECG images from PDFs or scanned paper records into WFDB-compliant digital signals through grid calibration, YOLOv12-based lead localization, and waveform extraction using Viterbi path search or an improved centerline method1. The protocol includes validation checkpoints (bounding-box overlays, trace overlays, and WFDB reload plots) to support quality assurance during digitization.

Converting ECG ...

Access restricted. Please log in or start a trial to view this content.

Disclosures

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

The authors have no competing financial interests or personal relationships that could have appeared to influence the work reported in this article.

Acknowledgements

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,

The authors thank Tam Duc Hospital for providing de-identified ECG reports and for institutional support during data collection.

Access restricted. Please log in or start a trial to view this content.

Materials

List of materials used in this article
NameCompanyCatalog NumberComments
GPU (runtime tests)NVIDIAGeForce RTX 3060 12 GBNVIDIA GeForce RTX 3060 12 GB used for runtime tests
NumPyNumPy1.26.4Numeric processing
OpenCVOpenCV4.10.0.84Image preprocessing (deskew, filtering)
Operating system(runtime tests)MicrosoftWindows 11Windows 11 used for runtime tests
PDF-to-image converterThis protocolV1PDF rasterization at 300 DPI; provide repository URL in Data Availability
PythonPython Software Foundation3.12.5Runtime environment
PyTorchPyTorch0.5.0Backend for YOLOv12
ScannerCanonDR-C240300 DPI, grayscale, PNG/TIFF recommended
scikit-imagescikit-image0.25.0Skeletonization and morphology (centerline)
UltralyticsUltralytics8.3.155YOLOv12 training/inference framework
wfdb (Python package)PhysioNet4.1.2WFDB export (.hea/.dat)

References

Loading...
$$\rightleftharpoonup{xx}$$ $$\longleftharp{xx}$$, $$\longrightharp{xx}$$,
  1. Muhammet, A., Fani, D., Christos, A., Idris, Z., Gruschen, R. V. Digitization and Linkage of PDF Formatted 12-Lead Electrocardiograms in Adult Congenital Heart Disease. CJC Pediatric and Congenit Heart Dis. 4 (5), 263-273 (2025).
  2. Baydoun, M., et al. High precision digitization of paper-based ECG records: A step toward smart machine learning. IEEE J Transl Eng Health Med. 7, 1-8 (2019).
  3. Demolder, A., et al. High precision ECG digitization using artificial intelligence. Biomed Signal Process Control. 72, 103331(2024).
  4. Prim, J., et al. A data pipeline for extraction and processing of electrocardiogram recordings. Comput Cardiol. 48, 1-4 (2021).
  5. Rautela, D., Bajeli, D., Kumar, M., Vaidya, A. Identifying cardiovascular disorders through ECG image analysis. Knowl-Based Syst. 186, 104925(2020).
  6. Reyna, M. A., et al. ECG-Image-Database: A dataset of ECG images with real-world imaging and patient annotations. arXiv. , (2024).
  7. Ribeiro, H., et al. Automatic 12-lead ECG classification using a convolutional network ensemble. Comput Cardiol. 47, 1-4 (2020).
  8. Jessy, K. S. J., Manikandan, D. G., Hemalatha, M. S., Veroncia, M. V. Detection of cardiovascular disease using ECG images in machine learning and deep learning. Int J Sci Res Sci Technol. 11, 131-139 (2024).
  9. Digitization of ECG records using signal extraction techniques. Karnaschandani, H., et al. 2024 Second International Conference on Data Science and Information System (ICDSIS), Hassan, India, , 1-8 (2024).
  10. Nguyen, C. V., Nguyen, H. N., Nguyen, D. A., Do, C. D. VinDigitizer: An image processing approach to digitize paper ECG records. Comput Cardiol. 51, 1-4 (2024).
  11. Patil, R., Narkhede, R. D., Vama, B., Suraliya, S., Raut, S. R. Auto lead extraction in ECG images: Identification of ECG paper records using deep learning. Biomed Signal Process Control. 72, 103339(2024).
  12. Santamaría, F., et al. ECGMiner: A flexible software for accurately digitizing ECG. Comput Methods Programs Biomed. 246, 108053(2024).
  13. Shivashankara, K. K., et al. An open ECG-image toolkit: ECG-ImageNet – an open image generation toolbox to facilitate deep learning-based electrocardiogram digitization. Biomed Signal Process. Control. 72, 103342(2024).
  14. Wang, L. H., et al. Paper-recorded ECG digitization method with automatic reference voltage selection for telemonitoring and diagnosis. Diagnostics. 14 (17), 1910(1910).
  15. Wang, T., Zhang, Y., Liu, X., Huang, Z., Qin, F. Automatic Detection of Arrhythmias Using a YOLO-Based Network with Long-Duration ECG Signals. Eng Proc. 2 (1), 84(2020).
  16. Wu, H., et al. A fully automated paper ECG digitisation algorithm using deep learning. Sci Rep. 12, 25284(2022).
  17. Júnior, O., et al. An automated machine learning method to efficiently classify the 12-lead ECG signal acquisition quality. Computing in Cardiology. 50, 1-6 (2023).
  18. Lence, A., et al. ECGtizer: A fully automated digitizing and signal recovery pipeline for electrocardiograms. arXiv. , (2024).
  19. Büyüksolak, O., Öksüz, İ Pic2Diagnosis: A Method for Diagnosis of Cardiovascular Diseases from the Printed ECG Pictures. Proc. IEEE EMBC. , (2025).

Access restricted. Please log in or start a trial to view this content.

Reprints and Permissions

Request permission to reuse the text or figures of this JoVE article

Request Permission

Tags

12 Lead ECGWaveform ExtractionSignal PreprocessingObject Detection ModelGrid DetectionSignal NormalizationQuality Control
Video Coming Soon

Related Articles