Skip to main content

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.

PyPI version Downloads Python 3.9+ License: MIT Author GitHub stars


🔍 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

# Standard installation (lightweight, zero OpenCV bloat)
pip install deeptrace-ela

# With OpenCV for sub-pixel morphological contour clustering
pip install deeptrace-ela[cv]

# With development and test 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"Forensic Verdict: {result.verdict}")        # 'SUSPICIOUS' or 'CLEAN'
print(f"Is Suspicious:    {result.is_suspicious}")   # True / False
print(f"Mean error:       {result.mean_error:.2f}")

# 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}) | peak delta: {box.peak_delta}")

# Export structured dictionary for JSON APIs
data = result.to_dict()

# Save amplified heatmap directly
result.save_heatmap("analyzed_ela.png")

🔬 Algorithm Specification

  1. Re-compression: The input image is converted to RGB and saved to an in-memory JPEG stream at quality $Q$ (standard $Q = 95$).
  2. 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)|$$
  3. Contrast Amplification: Differences are amplified dynamically by scaling factor $S = \min(15.0, 255 / \max(\Delta))$ to highlight microscopic compression rate mismatches.
  4. Adaptive Baseline Masking: An adaptive statistical threshold ($\mu + 3.5\sigma$) computes the localized anomaly score across non-edge ambient surface pixels.

👤 Author & Maintainer


📄 License

This project is licensed under the MIT License.

Metadata

Release files for deeptrace-ela 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deeptrace-ela 0.1.2
File Size Uploaded Provenance
deeptrace_ela-0.1.2.tar.gz 12.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for deeptrace-ela 0.1.2
File Interpreter ABI Platform
deeptrace_ela-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.9 kB

Release files / deeptrace_ela-0.1.2.tar.gz

Download URL deeptrace_ela-0.1.2.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ba79fa3d21214a2ad3528f9f27dbc20e043e561d6c0493d2681335a0a89fd01d
BLAKE2b-256 checksum
How to use checksums
5a68b7ecbfff3937ea30f20fef2007ee6b74cadcd8d504b082dda17df98f742b
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.2-py3-none-any.whl

Download URL deeptrace_ela-0.1.2-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7afecec05733985ebdf5ac84d2760141a2c5dafe448f9212415c8dfdc1a7452d
BLAKE2b-256 checksum
How to use checksums
86f00c8dffaf64de70efe8614a568eb71bff419285cce53e8b45dfea81073521
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.2

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page