How I Built a Lightweight Image Forensics Engine in Python (And Why Naive ELA Fails)
Description and use
A lightweight Python ELA engine that accurately detects tampering in scanned documents, avoiding false positives by using NIST‑calibrated resave, dynamic contrast amplification, and adaptive ambient thresholding.
Problem
Detecting subtle image tampering in scanned documents without generating false positives from high‑contrast text.
Outcome
deeptrace‑ela achieves sub‑100 ms latency, <30 MB RAM usage, and accurate detection of tampered regions in 1080p images without GPU.
Workflow
- Install deeptrace‑ela via pip
- Import analyze_ela in Python
- Run analyze_ela on an image with quality=95
- Inspect result.verdict, result.mean_error, and result.anomalies
- Save heatmap with result.save_heatmap
- Optionally run deeptrace‑ela from CLI with --output or --json
Evidence
Over the past few months, I built and open‑sourced deeptrace‑ela — a zero‑GPU, NIST‑grade Error Level Analysis (ELA) forensics engine in Python.
If you run that script on a real‑world document (like a scanned contract or a PDF receipt), it fails catastrophically.
We added three deterministic safeguards: NIST‑Calibrated Resave Tier (Q = 95), Dynamic Contrast Amplification, Adaptive Ambient Thresholding (μ + 3.5σ).
Execution speed: ~35ms – 85ms on a 1080p image on a standard laptop CPU
- Record date: 2026-10-25T18:26:13.135Z