DeepTrace ELA (Error Level Analysis) Forensics Engine
An open-source, NIST-grade Error Level Analysis (ELA) and JPEG compression artifact forensics toolkit developed by Shaheer Ul Hassan.
🔍 Overview
When an image is modified or spliced (such as pasting a fake signature, changing numbers on a document, or splicing digital elements), the newly pasted regions typically have a distinct JPEG compression history from the ambient background.
deeptrace-ela re-compresses the input image at a known quality level ($Q = 95$ by default), evaluates the absolute residual error between the input and re-compressed pixels, amplifies compression discrepancies, and detects anomalous noise clusters indicative of cut-and-paste manipulation.
Extracted from the DeepTrace document forensics pipeline.
🚀 Installation
pip install deeptrace-ela
Or install with development dependencies:
pip install deeptrace-ela[dev]
💻 CLI Usage
Analyze any image directly from your terminal:
# Basic ELA analysis (displays summary & saves heatmap to input_ela.png)
deeptrace-ela sample_check.jpg
# Save output heatmap to a custom file
deeptrace-ela contract.jpg --output heatmap.png
# Custom JPEG quality & amplification scale
deeptrace-ela invoice.png --quality 95 --scale 20.0
# Output structured JSON for automated pipelines
deeptrace-ela document.jpg --json
CLI Output Example
============================================================
DeepTrace ELA — Image Forensics Engine
Author: Shaheer Ul Hassan (https://shaheerulhassan.com/)
============================================================
Image: invoice.jpg (1920x1080)
Resave Q: 95
Max Delta: 84
Mean Error: 3.42
Std Error: 2.15
Threshold: 10.95 (ambient mean + 3.5σ)
Status: ⚠️ SUSPICIOUS (2 anomalous compression cluster(s) detected)
Detected Anomalies:
[#1] Bounding Box: [x=420, y=310, w=180, h=45] | Peak Delta: 68.2
[#2] Bounding Box: [x=915, y=740, w=120, h=35] | Peak Delta: 72.1
Heatmap saved to: invoice_ela.png
🐍 Python API
You can easily integrate deeptrace-ela into your Python scripts or web services:
from deeptrace_ela import analyze_ela
# Run ELA forensics analysis
result = analyze_ela("document.jpg", quality=95, scale=15.0)
print(f"Mean error: {result.mean_error:.2f}")
print(f"Suspicious: {result.is_suspicious}")
# Iterate over detected anomaly regions
for box in result.anomalies:
print(f"Anomaly at (x={box.x}, y={box.y}, w={box.w}, h={box.h})")
# Save or display the amplified heatmap
result.heatmap.save("analyzed_ela.png")
🔬 Algorithm Specification
- Re-compression: The input image is converted to RGB and saved to an in-memory JPEG stream at quality $Q$ (standard $Q = 95$).
- Differential Residual: Pixel-by-pixel absolute difference is computed between the original and the re-saved JPEG: $$\Delta(x, y) = |I_{orig}(x, y) - I_{resaved}(x, y)|$$
- Contrast Amplification: Differences are amplified dynamically by scaling factor $S = \min(15.0, 255 / \max(\Delta))$ to highlight microscopic compression rate mismatches.
- Adaptive Baseline Masking: An adaptive statistical threshold ($\mu + 3.5\sigma$) computes the localized anomaly score across non-edge ambient surface pixels.
👤 Author & Maintainer
- Author: Shaheer Ul Hassan
- Website: shaheerulhassan.com
- GitHub: @samjanjua6
- DeepTrace Project: samjanjua6/DeepTrace
- LinkedIn: Shaheer Ul Hassan
📄 License
This project is licensed under the MIT License.
Metadata
Release files for deeptrace-ela 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| deeptrace_ela-0.1.0.tar.gz | 9.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deeptrace_ela-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / deeptrace_ela-0.1.0.tar.gz
| Download URL | deeptrace_ela-0.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43d3dd1ada83a46ef539cbbd0a0db1204b475b63dda6a81af130247913a93ee2
|
|
BLAKE2b-256 checksum How to use checksums |
e488543460a121272925348f8dbff69202341443e6145d1710a170b00a1f67a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / deeptrace_ela-0.1.0-py3-none-any.whl
| Download URL | deeptrace_ela-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f219e362b464ecd5c67c57f6083ca5d13488494099b69369eb4f79d13b877279
|
|
BLAKE2b-256 checksum How to use checksums |
5429749d19dc8f5c661cea35b36a7bfe679c7cbe8939d8658438d24057ccc329
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for deeptrace-ela 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.