Skip to main content

SpliceTrail

Finds where a small region of an image was copied from, across a collection of images or within one image, even after recoloring, JPEG recompression and shrinking. Every reported region comes with a significance score (an a-contrario NFA) you can put in a report.

The default search covers the common edits and is quick; --thorough also checks mirrored, enlarged and rotated copies at about 9x the time (see Quick or Thorough).

Install

pip install splicetrail   # from PyPI

# Or the latest code straight from GitHub:
pip install "git+https://github.com/jayashankarvr/splicetrail.git"

# With optional features (quote the brackets; zsh treats them as a glob):
pip install "splicetrail[api]"    # REST API
pip install "splicetrail[bench]"  # Benchmark harness (OpenCV baseline)
pip install "splicetrail[hash]"   # Perceptual image hashes (PDQ, pHash)
pip install "splicetrail[full]"   # Everything

# From a source checkout, with the development tools:
pip install -e ".[dev]"

Requires Python 3.9-3.13 and: numpy, scipy, pillow, scikit-learn, faiss-cpu, click

Quick Start

The API has no authentication unless SPLICETRAIL_API_KEY is set (see REST API).

# Start the API server (published on 127.0.0.1:8000, index kept in a volume)
export SPLICETRAIL_API_KEY="$(openssl rand -hex 32)"
docker compose up

# Index an image
curl -X POST "http://localhost:8000/index?image_id=target_001" \
  -H "X-API-Key: $SPLICETRAIL_API_KEY" -F "file=@target.jpg"

# Match a source image
curl -X POST "http://localhost:8000/match?return_heatmap=true" \
  -H "X-API-Key: $SPLICETRAIL_API_KEY" -F "file=@source.jpg"

Option 2: Python Module

# Start API server (listens on 127.0.0.1 only)
python -m splicetrail serve --port 8000

# Show version
python -m splicetrail version

# Run the test suite (source checkout with pip install -e ".[dev]" only)
python -m splicetrail test

Option 3: Makefile

make install-dev  # Install in development mode with every extra
make test         # Run tests
make serve        # Start API server
make docker-build # Build Docker image

Usage

CLI

# Match source against target
splicetrail match source.jpg target.jpg

# With options: patch size, heatmap, JSON forensic report
splicetrail match source.jpg target.jpg -p 6 -o heatmap.png -j report.json -v

# Also check mirrored, enlarged and rotated copies (slower)
splicetrail match source.jpg target.jpg --thorough

# Index a directory (writes myindex.index, myindex.meta.json, myindex.engine.json;
# with --thorough also myindex.rotated.*)
splicetrail index images/ -o myindex

# Search against the saved index; patches are reloaded from the indexed files
splicetrail search query.jpg myindex -k 5

# Scan many questioned images, holding the false discovery rate at 5%
splicetrail scan myindex questioned/*.jpg --fdr 0.05

# Visual report a person can review (plus the JSON record)
splicetrail match source.jpg target.jpg --html report.html -j report.json

# Which images in a folder share copied regions (and, optionally, copy-moves)
splicetrail provenance photos/ --copy-moves --json links.json --dot links.dot

Python API

Basic Usage

from splicetrail import ForensicsEngine
from splicetrail.engine import load_image

engine = ForensicsEngine()
engine.index_target(load_image("suspect_photo.jpg"), "suspect_001")
engine.index_target(load_image("crime_scene.jpg"), "scene_001")

result = engine.match(load_image("questioned.jpg"))

for region in result.significant_regions:
    print(f"Copied from {region.image_id}")
    print(f"  source bbox {region.source_bbox} -> target bbox {region.target_bbox}")
    print(f"  {len(region.matches)} agreeing patches, log10 NFA {region.log10_nfa:.1f}")
    print(f"  color transform M={region.color_M.round(3)}, b={region.color_b.round(3)}")

# Where in the questioned image the copied pixels are (bool mask)
mask = result.localization.mask

log10_nfa is the log of the expected number of regions at least this good in images with no copy at all. -5 means you'd expect one such coincidence in 100,000 comparable searches. Regions are reported as significant when NFA < 1 (Config.max_nfa).

Individual Match objects carry a probability, which is a per-patch chi-square goodness-of-fit p-value. It's a pre-filter, not evidence on its own: small patches fit each other by chance all the time.

Custom Configuration

from splicetrail import ForensicsEngine, Config

config = Config(
    patch_size=6,            # 3-16; 5 is the benchmarked default
    stride=2,                # skip positions for speed
    noise_sigma=0.03,        # expected noise; raise for heavily compressed images
    max_nfa=0.01,            # stricter significance
    pyramid_enabled=False,   # index targets at full size only (faster)
    max_targets=100,         # evict least recently indexed targets past this
)
engine = ForensicsEngine(config)

Copy-Move Within One Image

result = engine.match_self(load_image("questioned.jpg"))
for region in result.significant_regions:
    print(region.source_bbox, "duplicated at", region.target_bbox, region.log10_nfa)

The image is matched against itself, ignoring offsets shorter than twice the patch size. Each duplicated pair is reported once; localization covers both copies. Repetitive texture (brick, gravel, lattices) matches itself at many offsets, so a region only counts when its offset clearly beats every other offset its patches support - a region-level ratio test. On 60 recolored real-photo copy-moves plus 60 clean crops it reports no false regions at any threshold and finds 70-82% of the copies (NFA 1e-4 to 10; python -m splicetrail.bench.runner --dataset photos --task copymove --n 60 --negatives 60 --calibrate). Content that really is duplicated is still reported: scikit-image's grass and gravel photos each contain a cloned strip, and SpliceTrail finds them, so the benchmark leaves those photos out.

With mirroring on (flip_invariant, part of thorough), mirrored copies are searched too, which raises a trap: a left-right symmetric object (a face, a facade, the round edge of a microscope or fundus photo) matches its own mirror image. Its two halves sit side by side on the same rows, so mirrored regions shaped like that are dropped. The price is a mirrored copy pasted right beside its source at the same height, which looks exactly like a symmetric object: 1 of 40 copies in the mirrored copy-move benchmark when this rule was added (found at NFA 1e-3: 72.5% -> 70%, still no false regions; --dataset photos --task copymove --flip --thorough --calibrate).

JPEG-Aware Noise

A JPEG file's quantization tables say how much rounding error to expect. The CLI and API read them automatically; from Python pass them yourself:

from splicetrail.jpeg import quantization_sigma

engine.index_target(load_image(path), path, image_path=path)   # read from the file
result = engine.match(image, jpeg_sigma=quantization_sigma("questioned.jpg") or 0.0)

Quick or Thorough

Most copied fragments are cut out (cropped), recolored, recompressed or shrunk, and the default search covers exactly those. Mirrored, enlarged and rotated copies are rarer and cost several extra searches each, so they are checked only when asked for:

engine = ForensicsEngine(Config(thorough=True))   # CLI: splicetrail match --thorough ...
Edit to the copied fragment default thorough
cut out / cropped, moved yes yes
recolored (brightness, contrast, colour grade, tone curve) yes yes
JPEG recompression yes yes
shrunk yes, cross-image (target pyramid) yes, cross-image
mirrored (left-right; up-down too, as mirror plus 180 degrees) - yes
enlarged - yes, cross-image (query_scales)
rotated - yes, cross-image (a second, ring-based search)

Not checked even with thorough: a copy that is both rotated and rescaled; rotated or rescaled copies within one image (copy-move gets mirroring only); non-uniform scaling, shear or perspective. thorough takes about 9x as long as the default (11.5 s against 1.3 s per pair on 10 + 10 photo splices: python -m splicetrail.bench.runner --dataset photos --n 10 --negatives 10 --no-baselines, with and without --thorough) and holds a second index (about twice the memory); a thorough splicetrail index writes .rotated.* files next to the usual three, which belong with it.

thorough combines its searches into one result and multiplies every region's NFA by the number of searches combined, so the NFA keeps its meaning. With splicetrail index, decide when indexing: splicetrail search and splicetrail scan follow the index. The pieces can also be switched on one by one (flip_invariant, query_scales, rotation_invariant).

Mirrored Copies

Config(flip_invariant=True) (part of thorough) also searches the mirrored query, so a fragment that was flipped before pasting is found (Match.mirrored, CoherentRegion.mirrored). Measured during development on photo splices where half the fragments are mirrored (--dataset photos --flip in the benchmark runner), it doubled recall (0.45 -> 0.90); on copy-move in real photos it added no false alarms. It takes about 1.5x as long (the mirrored pass runs on a second thread).

Rotated Copies (experimental)

Config(rotation_invariant=True) compares patches as colour samples on rings around their centres instead of as squares, and groups matches by rotation + translation (it indexes targets at full size only; the pyramid isn't supported yet). The ring descriptor doesn't change when a patch turns, and each match's angle is measured by aligning the two sets of rings, so no per-patch orientation has to be estimated. On 20 photo splices rotated by up to 180 degrees (plus 20 unrelated pairs) it found 60% at NFA < 10^-3 with IoU 0.51, AUC 0.995 and no false regions when measured during development (the ring design replaced one that turned each patch to its own estimated orientation; see the CHANGELOG for 0.3.0). It's off by default because it is slower (about 20 s per 192 px pair) and has limits:

  • The rings read about twice the patch width, so a copy narrower than about 17 px (patch 5) can't be found.
  • Smooth, gently varying content has little structure around a ring to match on.
  • Within one image, a round object with a radial pattern matches itself turned; regions that turn about a point inside both copies are dropped for that reason.
  • Rotated copy-moves (a region copied and turned within the same image) are mostly missed. The repeated-texture test copy-move needs compares plain offsets, which a rotation spreads out; without it, edges matching edges at any angle raise alarms on over a third of clean photos, and a version comparing whole rigid transforms didn't separate the two on our test images. Cross-image search (a rotated fragment from another image) is what this mode handles. Switched on by hand for copy-move, it also raises more alarms on clean images: in development runs on CoMoFoD (25 copies + 25 originals each) it found 28% of rotated copies with 1 original flagged, and 36% of plain translated copies with 2 originals flagged, where the default then found 40% and flagged none (44% and none on 0.3.0). thorough leaves it out of copy-move for that reason.

Large Collections

The index (index_type, default "ivfpq") stores descriptors with product quantization in an inverted file once ivf_train_size patches (default 50,000) are indexed; below that, search is exact. On 200,000 descriptors from the benchmark photos it was 3.6x smaller than the exact index (6.0 vs 21.6 MB) and answered 20,000 queries about 45x faster (python -m splicetrail.bench.index_size; timings depend on the machine). During development, real-photo splices forced to use it gave the same results as the exact index (IoU 0.818, recall 0.975, no false regions). Only candidate generation is approximate - every candidate is still verified against real pixels. index_type="flat" keeps search exact at any size.

Targets keep their pixels once (uint8) rather than a patch per position, which is most of the memory regardless of the index.

Multi-Scale Matching

Targets are indexed at full, 3/4 and 1/2 size by default, so a copy that was shrunk before pasting is still found. Matches record the level they came from in target_scale. When this became the default (measured during development on 60 spliced + 60 unrelated CASIA v2 pairs) it took IoU from 0.27 to 0.37 and recall from 0.29 to 0.39 with no extra false regions (1 in 120 pairs either way), for about 17% more time per image.

config = Config(pyramid_scales=[1.0, 0.5, 0.25])   # or pyramid_enabled=False
engine = ForensicsEngine(config)

The pyramid only covers copies that got smaller. For copies that were enlarged, query_scales=[1.0, 0.75, 0.5] also searches the questioned image shrunk to those sizes. Each extra scale is another full search, and the NFA is multiplied by the number of passes. On 40 + 40 CASIA v2 pairs it left the share of splices found at NFA < 10^-3 at 42.5% and raised it from 45% to 47.5% at NFA < 1, at 3x the time, so it's off by default and part of thorough. To reproduce, compare python -m splicetrail.bench.runner --dataset casia2 --n 40 --negatives 40 --calibrate with the same command plus --query-scales 1.0 0.75 0.5.

Heatmap and Report

from splicetrail.report import build_report, write_report

result = engine.match(source, return_heatmap=True)
result.heatmap          # (H, W) in [0, 1] over the best region's target image

report = build_report(result=result, config=engine.config,
                      source_path="questioned.jpg", source_image=source)
write_report(report, "report.json")

Save and Load an Index

engine = ForensicsEngine()
for path in paths:
    engine.index_target(load_image(path), path, image_path=path)
engine.save("myindex")

# Later, possibly in another process. Matching settings can be overridden;
# patch size, stride and pyramid always come from the saved bundle.
engine = ForensicsEngine.load("myindex", max_nfa=0.1)
result = engine.match(source)

Patches aren't stored in the bundle. They're re-extracted from image_path the first time a target is needed, so keep the indexed files where they were.

REST API

Without SPLICETRAIL_API_KEY there is no authentication: anyone who can reach the port can index, match and delete images. The server therefore listens on 127.0.0.1 by default, and warns when started on another address without a key. With the key set, every request needs an X-API-Key header, except the probes /health/live and /health/ready.

# Local use (127.0.0.1:8000, no key needed)
python -m splicetrail serve --port 8000

# Reachable from other machines: set a key, then send it with every request
export SPLICETRAIL_API_KEY="$(openssl rand -hex 32)"
python -m splicetrail serve --host 0.0.0.0 --port 8000
curl -H "X-API-Key: $SPLICETRAIL_API_KEY" http://localhost:8000/health

# Keep the index across restarts
export SPLICETRAIL_INDEX_DIR=/var/lib/splicetrail
python -m splicetrail serve

Server settings (engine settings are under Environment Variables):

Variable Default Effect
SPLICETRAIL_API_KEY unset: no authentication Require X-API-Key on every endpoint but the two probes (401 otherwise)
SPLICETRAIL_INDEX_DIR unset: in memory, lost on restart Load the index from this directory at startup and save it after every index and delete; indexed images are kept there as PNGs
SPLICETRAIL_MAX_TARGETS 1000 Past this many targets, the oldest is evicted
SPLICETRAIL_MAX_IMAGE_PIXELS 500000 Larger /index and /match uploads get 413
SPLICETRAIL_LOCK_TIMEOUT 30 Seconds a request waits for the engine before 503

Uploads are capped at 50 MB. Requests that use the engine take turns, and one that has started can't be cancelled; it finishes even if the client goes away, which is why the pixel cap exists. /hash?algorithm=photodna needs both SPLICETRAIL_API_KEY and SPLICETRAIL_PHOTODNA_KEY. Details, status codes and examples: docs/API.md; security notes: SECURITY.md.

API Endpoints:

  • GET / - Health check
  • GET /health - Health, index counts, target cap, whether the index is persistent
  • GET /health/live - Kubernetes liveness probe
  • GET /health/ready - Kubernetes readiness probe
  • GET /config - Get current configuration
  • POST /index - Upload and index an image
  • POST /match - Match an image against indexed targets
  • GET /targets - List indexed images
  • DELETE /targets/{id} - Remove an indexed image
  • POST /hash - Perceptual hashes, checked against the server's hash list

Interactive Docs: http://localhost:8000/docs API Documentation: See docs/API.md for details

Example: Python Client

import os
import requests

BASE_URL = "http://localhost:8000"
HEADERS = {"X-API-Key": os.environ.get("SPLICETRAIL_API_KEY", "")}

# Index a target
with open("target.jpg", "rb") as f:
    response = requests.post(f"{BASE_URL}/index", params={"image_id": "target_001"},
                             files={"file": f}, headers=HEADERS)
    print(response.json())

# Match a source
with open("source.jpg", "rb") as f:
    result = requests.post(f"{BASE_URL}/match", files={"file": f}, headers=HEADERS).json()

if result["detected"]:
    for region in result["coherent_regions"]:
        if region["significant"]:
            print(region["image_id"], region["source_bbox"], region["log10_nfa"])

Environment Variables

Configure SpliceTrail via environment variables:

export SPLICETRAIL_PATCH_SIZE=5             # Patch size (3-16)
export SPLICETRAIL_STRIDE=1                 # Patch stride
export SPLICETRAIL_K_NEIGHBORS=8            # Nearest neighbours per source patch
export SPLICETRAIL_DISTANCE_THRESHOLD=0.5   # Max squared descriptor distance
export SPLICETRAIL_MIN_PROBABILITY=0.01     # Per-patch fit p-value floor
export SPLICETRAIL_NOISE_SIGMA=0.02         # Expected noise (0-1 scale)
export SPLICETRAIL_MAX_NFA=1.0              # Significance threshold for regions
export SPLICETRAIL_ENTROPY_THRESHOLD=       # Optional texture floor in bits (unset = off)
export SPLICETRAIL_PYRAMID_ENABLED=false    # Index targets at full size only
export SPLICETRAIL_THOROUGH=true            # Also check mirrored, enlarged and rotated copies
export SPLICETRAIL_MAX_TARGETS=1000         # Evict least recently indexed targets

The API server's own settings (SPLICETRAIL_API_KEY, SPLICETRAIL_INDEX_DIR and the limits) are listed under REST API.

Deployment

Docker

The image runs the server on 0.0.0.0 inside the container and keeps the index in /data (SPLICETRAIL_INDEX_DIR=/data), so mount a volume there. Publish the port on the host's loopback, or set SPLICETRAIL_API_KEY.

# Build image
docker build -t splicetrail .

# Run container: loopback only, key required, index in a named volume
docker run -p 127.0.0.1:8000:8000 -e SPLICETRAIL_API_KEY -v splicetrail-data:/data splicetrail

# Or keep the index in ./data. Create it first (it must be writable by uid
# 1000, the server user): Docker would create a missing one owned by root,
# and the server would stop with "Can't use index dir /data"
mkdir -p data
docker run -p 127.0.0.1:8000:8000 -e SPLICETRAIL_API_KEY -v ./data:/data splicetrail

# Or use docker compose (publishes 127.0.0.1:8000, named volume for /data,
# passes SPLICETRAIL_API_KEY through from the shell or an .env file)
docker compose up

# With Nginx reverse proxy (publishes port 80 on every interface: set
# SPLICETRAIL_API_KEY first, and enable HTTPS in nginx.conf)
docker compose --profile with-nginx up

Kubernetes

Each server process holds its own index, so run one replica: more replicas would each have different targets (a shared index isn't supported). Keep the index on a PersistentVolumeClaim through SPLICETRAIL_INDEX_DIR, and use the Recreate strategy so an old and a new pod never write the same index.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: splicetrail-api
spec:
  replicas: 1   # the index is per process; scaling out isn't supported
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: splicetrail
  template:
    metadata:
      labels:
        app: splicetrail
    spec:
      containers:
      - name: splicetrail
        image: splicetrail:latest
        ports:
        - containerPort: 8000
        env:
        - name: SPLICETRAIL_MAX_TARGETS
          value: "100"
        - name: SPLICETRAIL_INDEX_DIR
          value: /data
        - name: SPLICETRAIL_API_KEY
          valueFrom:
            secretKeyRef:
              name: splicetrail
              key: api-key
        livenessProbe:
          httpGet:
            path: /health/live
            port: 8000
          initialDelaySeconds: 10
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health/ready
            port: 8000
          initialDelaySeconds: 5
          periodSeconds: 5
        volumeMounts:
        - name: splicetrail-data
          mountPath: /data
      volumes:
      - name: splicetrail-data
        persistentVolumeClaim:
          claimName: splicetrail-pvc

Image hashing

splicetrail hash computes perceptual hashes and checks them against lists of known hashes, such as the lists organisations share through Meta's ThreatExchange or older databases built with pHash. A hash answers "is this the same picture, give or take resizing, recompression and small edits?". It doesn't say where a piece of a picture came from; that is what SpliceTrail's region search is for.

A list only works with hashes made the same way, bit for bit, as the ones in it, so every algorithm here comes from its reference library:

Algorithm What it is Bits Comes from Match at distance
pdq Meta's PDQ, the format of ThreatExchange lists 256 pdqhash (MIT, bundling Meta's BSD C++), pip install "splicetrail[hash]" 31 or less
phash DCT pHash as computed by the Python imagehash library 64 imagehash, same extra 10 or less
phash-lib ph_dct_imagehash from libpHash (phash.org), for databases built with the C library 64 your own libpHash install 10 or less
photodna Microsoft PhotoDNA - Microsoft's PhotoDNA Cloud Service decided by the service

pdq and phash hashes of the same image are different numbers and are never compared with each other; neither is phash with phash-lib.

# Print the hashes of some images (every local algorithm installed here)
splicetrail hash photo.jpg other.png

# Match against a list; rows are algorithm,hash,id (a header line is fine)
splicetrail hash photo.jpg --against known.csv

# Also hash the eight rotations and flips, so rotated or mirrored copies match
splicetrail hash photo.jpg --against known.csv --thorough

# One algorithm, a stricter distance, and the result as JSON
splicetrail hash photo.jpg -a pdq --against known.csv --max-distance 20 --json out.json
photo.jpg pdq d8f8f0cee0f4a84f0637022a078f67f0b36e2ed596621e1d33e6339c4e9c9b22 quality=100
photo.jpg phash aca29c1c33dc23d7
  match bridge (pdq) distance=0 variant=original

A list can also leave out the algorithm column (hash,id, or one bare hash per line) if you name its algorithm with a single --algorithm, e.g. splicetrail hash photo.jpg -a pdq --against pdq-list.txt.

In Python, splicetrail.hashing.hash_image, load_hash_list and match_hashes do the same (load_hash_list(path, algorithm="pdq") for lists without an algorithm column). On the server, POST /hash does the same (see docs/API.md), with the list given to splicetrail serve --hash-list known.csv (or SPLICETRAIL_HASH_LIST) so it stays on the server. The JSON forensic report records each input image's hashes, for the local algorithms installed, next to its SHA-256.

Quality. PDQ gives each hash a quality from 0 to 100. Near-blank and flat images score low, and their hashes match too much by chance, so PDQ hashes below quality 50 aren't matched (--min-quality 0 matches them anyway). They are still printed, and listed as skipped. pHash has no quality score.

How the distances were chosen

python -m splicetrail.bench.hash_robustness hashes the 13 scikit-image benchmark photos and edited copies of each, and prints the largest distance between a photo and its edited copy, and the smallest distance between two different photos:

pdq phash
resized to 0.5x (largest) 58 (brick; next is grass, 28) 2
resized to 2x (largest) 10 2
JPEG quality 70 (largest) 2 2
colour grade 0.15 (largest) 6 2
5% cropped (largest) 110 22
two different photos (smallest) 108 20
distance used 31 10

For phash, 10 sits well inside the gap: edited copies move 2 bits at most and different photos are at least 20 apart. For pdq, 31 is the threshold Meta publishes for PDQ, and we keep it. The one miss is the brick photo halved in size (58 bits): it is an even, fine texture with little large-scale structure, and PDQ's hash of such an image changes a lot when it is shrunk, whatever resampling filter is used. Ordinary photos stayed under 31. Some tools (python-threatexchange, HMA) hash the full image without the 512 px downsample SpliceTrail applies, so their hashes of large images can differ from SpliceTrail's by a few bits, well inside 31. The benchmark is small, so treat these numbers as a sanity check rather than error rates; --max-distance changes the cutoff. The phash-lib default copies phash's; it hasn't been measured, because libpHash isn't installed where these were run.

What hashes don't survive

Perceptual hashes describe the whole picture, so they fail when the picture as a whole changes: cropping, rotation by angles other than 90 degrees, and large local edits such as pasting in or removing a big object. Even a 5% crop pushed all 13 photos above past the PDQ threshold, and 2 of them past the pHash one. Rotations by 90 degrees and mirror images match only with --thorough. For those cases, and for finding where part of an image came from, use splicetrail match and splicetrail search, which compare regions rather than whole images.

Licensing and privacy

  • pdqhash (MIT, bundling Meta's BSD C++) and imagehash (BSD) are installed with the hash extra.
  • libpHash is GPLv3. SpliceTrail is Apache-2.0 and doesn't ship it or link to it at build time; phash-lib only works if you install libpHash yourself (for example apt install libphash0, or set SPLICETRAIL_PHASH_LIB to the .so). SpliceTrail's tests check phash-lib only against a mocked library, not the real libpHash, so check a few hashes against libpHash's own output before relying on it.
  • PhotoDNA needs a licence from Microsoft and a PhotoDNA Cloud Service key in SPLICETRAIL_PHOTODNA_KEY. Using it sends the image to Microsoft. SpliceTrail never does that unless photodna is asked for by name, and the report never uses it. The PhotoDNA client is tested only against a mocked service.

How it works

A diagram of the architecture and the workflow is in docs/architecture.drawio (two pages; open it in draw.io / diagrams.net).

  1. Extract every patch (default 5x5) and drop flat ones. Targets are also indexed at 3/4 and 1/2 size, for copies that were shrunk.
  2. Describe each patch by its normalized luminance pattern: grey levels minus their mean, scaled to unit length. Brightness and contrast drop out, and mild color grades barely move it. Luminance is used because JPEG keeps it at full resolution while it subsamples color.
  3. Nearest-neighbour search (FAISS): exact for small collections, a compressed inverted-file index past 50,000 patches.
  4. Per-patch pre-filter: fit grey-level gain and offset, chi-square test the residual, with the noise level read from the JPEG quantization tables when there are any. Pixels clipped at 0 or 255 are ignored, since a recolor that saturates breaks the model there.
  5. Cluster the surviving matches by translation, per target image and scale, and (across images) split each cluster into spatially connected parts, so chance matches elsewhere at the same offset don't dilute a real copy.
  6. For each cluster, fit one 3x3 color transform over all its pixels, keep the patches whose luminance agrees with it, and compute the region's NFA: how many regions this consistent you'd expect by chance, given how often patches matched at all and how many regions were tried (offsets, positions, region sizes, scales, passes).

thorough repeats this on the mirrored and shrunk questioned image, and runs a second search that compares patches as rotation-invariant rings; all of it is counted in the NFA.

Handles brightness, contrast, color grading (any affine color transform), JPEG recompression and, with the pyramid, downscaled copies; mirrored, enlarged and rotated copies with the options above. It does not handle non-uniform geometric distortion.

A significant NFA means "not chance", which isn't the same as "copied": content that is genuinely identical by design (the same logo, text glyphs, identically drawn shapes) matches for real and will be reported. Look at the region before concluding.

Benchmark

python -m splicetrail.bench.runner scores SpliceTrail (and a RootSIFT + RANSAC baseline) on one of several datasets:

--dataset What it is
synthetic (default) procedural textures with recolored splices; exact ground truth
photos splices between real photos bundled with scikit-image (real noise and JPEG history)
casia2 CASIA v2 cross-image splices with their real donor images; python -m splicetrail.bench.download casia2 fetches it from Kaggle (as do coverage and comofod) (needs a Kaggle API token in KAGGLE_API_TOKEN, KAGGLE_ACCESS_TOKEN or ~/.kaggle/access_token, or KAGGLE_USERNAME/KAGGLE_KEY)
coverage COVERAGE copy-moves: 100 forgeries whose originals hold similar-but-genuine objects (the originals are the negatives). Masks are where each forgery differs from its original, which marks the pasted copy but not its source, so only recall of the copy is reported and a region counts as found when either half lands on the copy
comofod CoMoFoD copy-moves, the 120 base cases; masks mark both copies; --category translation|rotation|scaling
manifest your own data: a CSV of donor,tampered,mask,label

--calibrate checks the NFA's promise directly: for a range of thresholds it reports false regions per image pair (should stay at or below the threshold) next to recall. On 40 photo splices + 40 unrelated pairs at JPEG quality 75 it reports no false regions at any threshold up to 10 and 92.5% recall from NFA < 10^-4 on (python -m splicetrail.bench.runner --dataset photos --n 40 --negatives 40 --jpeg 75 --calibrate).

Synthetic run (96x96 images, 24x24 splice, color grade 0.15, 20 spliced + 20 clean pairs; python -m splicetrail.bench.runner --n 20 --negatives 20, plus --jpeg 85 for the second row):

IoU Precision Recall Detection AUC s / image
SpliceTrail, uncompressed 0.85 0.95 0.89 0.96 0.6
SpliceTrail, JPEG q85 0.78 0.97 0.81 0.95 0.6
RootSIFT + RANSAC, uncompressed 0.00 0.70 0.00 0.75 0.1

The clean pairs contain hard-edged disks, and two disks of the same radius are pixel-identical, so some "false" detections there are real matches (see the note above). Synthetic data is a sanity check, not a substitute for a real forensic dataset.

CASIA v2 (real cross-image splices with their actual donor images; 40 spliced + 40 unrelated pairs, python -m splicetrail.bench.runner --dataset casia2 --n 40 --negatives 40 --calibrate; the baseline row used --n 60 --negatives 60):

IoU Precision Recall Detection AUC Found at NFA < 10^-3 s / image
SpliceTrail 0.34 0.97 0.37 0.79 42.5% 5.6
RootSIFT + RANSAC (60 + 60 pairs) 0.18 0.95 0.19 0.82 - 0.02

Real splices are much harder than the generated ones. SpliceTrail finds a little over 40% of them and stays precise: no alarm on any unrelated pair at any threshold, and one region in the 80 pairs that landed beside a splice instead of on it. Most of the misses are copies that were enlarged before pasting (about half of CASIA's splices are scaled up 1.15-2.5x), nearly flat regions with no texture to match, and very small splices. query_scales=[1.0, 0.75, 0.5] is meant for enlarged copies, but on the same pairs it only raises the share found at NFA < 1 from 45% to 47.5% (42.5% at NFA < 10^-3, unchanged), adds misplaced regions on spliced images (5 in the 80 pairs) and takes 3x as long, so it stays opt-in (same command plus --query-scales 1.0 0.75 0.5).

Copy-move (--task copymove on photos, or the standard sets). Each row is python -m splicetrail.bench.runner --calibrate with, in order: --dataset photos --task copymove --n 60 --negatives 60; --dataset comofod --category translation|rotation|scaling --n 25 --negatives 25; --dataset coverage --n 100 --negatives 100. "Found" is recall in the calibration table at that NFA.

Dataset Found at NFA < 10^-3 Found at NFA < 1 Clean images with an alarm (NFA < 10^-3)
Photo crops, recolored copies (60 + 60) 72% 80% 0%
CoMoFoD translation (25 + 25) 44% 48% 0%
CoMoFoD rotation (25 + 25) 20% 20% 4%
CoMoFoD scaling (25 + 25) 16% 16% 4%
COVERAGE (100 + 100) 31% 33% 4%

Copy-move is the harder task. Rotated and rescaled copies within one image aren't handled yet (rotation mode works across images only), and the clean images in CoMoFoD and COVERAGE are full of objects that genuinely repeat (identical printed logos, rows of windows, similar-but-genuine objects by design in COVERAGE). Those are real duplicates as far as pixels go, and SpliceTrail can't yet tell them from a pasted copy; that, more than chance, is where the alarms on clean images come from. During development, splitting a match cluster into connected parts found many more copy-moves but also flagged 12-28% of the clean images, so it is used for cross-image search only (see the CHANGELOG for 0.3.0).

Project structure

src/splicetrail/
    extraction/    # patch extraction, entropy, image pyramids, rotation rings
    descriptors/   # luminance-pattern descriptor
    search/        # FAISS index (exact or IVF-PQ, with real deletes)
    verification/  # affine color fit, chi-square test, coherence, NFA, FDR
    aggregation/   # heatmap, localization, match lists
    bench/         # datasets (synthetic, photos, CASIA v2, COVERAGE, CoMoFoD),
                   # calibration, baselines, downloader, hash robustness
    engine.py      # main API
    hashing.py     # perceptual hashes (PDQ, pHash, libpHash) and hash lists
    photodna.py    # PhotoDNA Cloud Service client
    jpeg.py        # noise level from JPEG quantization tables
    scale.py       # native-scale cue for the report
    provenance.py  # which images share copied regions
    visual.py      # HTML report
    report.py      # versioned JSON forensic report
    cli.py         # command line interface
    api.py         # REST API (FastAPI)

Development

pip install -e ".[dev,api,hash,bench]"   # or: make install-dev
pytest tests/                            # or: make test
make lint                                # ruff, black --check, mypy

See CONTRIBUTING.md.

License

Apache 2.0

Metadata

Release files for splicetrail 0.3.1

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

Source distribution (sdist)

Source distribution for splicetrail 0.3.1
File Size Uploaded Provenance Actions
splicetrail-0.3.1.tar.gz 217.7 kB Without provenance Details for splicetrail-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for splicetrail 0.3.1
File Interpreter ABI Platform Actions
splicetrail-0.3.1-py3-none-any.whl Python 3 none any Details for splicetrail-0.3.1-py3-none-any.whl

Total release size: 359.1 kB

Release files / splicetrail-0.3.1.tar.gz

Download URL splicetrail-0.3.1.tar.gz
Size 217.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c9d68055d56ede7246c9b06d1b1d90043a4886bbc5198621912c5c214f9a7d35
BLAKE2b-256 checksum
How to use checksums
516a6a1057d31de54fd231a22eb24b9b22f890e96e9b71c7cc411d69c709b94a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / splicetrail-0.3.1-py3-none-any.whl

Download URL splicetrail-0.3.1-py3-none-any.whl
Size 141.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f294f95c312abed114c842f9a728aae91ac3bed179427e70780938d98976f6cf
BLAKE2b-256 checksum
How to use checksums
d47b2a5d18f5fe26fbebe851c5d1e1d312504243ae432a0d654ba5692427e34b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Security for splicetrail 0.3.1

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.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files No provenance

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