Skip to main content

High-performance Python port of mapbox/pixelmatch for perceptual image comparison

Project description

pixelmatch-fast

Build codecov Python 3.10+ License: MIT PyPI - Downloads

High-performance Python port of mapbox/pixelmatch for perceptual image comparison

Pixelmatch is a tool that automatically highlights differences between two images while ignoring anti-aliasing artifacts.

For more information about pixelmatch capabilities and examples, see the mapbox/pixelmatch repository.

This project tries to stay up to date with the current pixelmatch version (currently matches with v7.1.0).

Similar Projects

This project is similar to pixelmatch-py. The key difference is that pixelmatch-fast is much faster by leveraging numpy for array operations and numba for JIT compilation.

Use pixelmatch-py if you want a clean port with very little dependencies, use pixelmatch-fast if you need high performance.

Installation

Install the package:

pip install pixelmatch-fast

CLI Usage

$ pixelmatch --help

Usage: pixelmatch [OPTIONS] IMG1 IMG2

  Compare two images pixel-by-pixel and visualize differences.

Options:
  --version              Show the version and exit.
  -o, --output PATH      Path to save diff image (PNG format)
  -t, --threshold FLOAT  Matching threshold (0 to 1); smaller is more
                         sensitive  [default: 0.1]
  --include-aa           Count anti-aliased pixels as different
  -a, --alpha FLOAT      Opacity of original image in diff output  [default:
                         0.1]
  --aa-color TEXT        Color of anti-aliased pixels (R,G,B)  [default:
                         255,255,0]
  --diff-color TEXT      Color of different pixels (R,G,B)  [default: 255,0,0]
  --diff-color-alt TEXT  Alternative color to differentiate between "added" and "removed" parts (R,G,B)
  --diff-mask            Draw diff over transparent background
  --help                 Show this message and exit.

Example (using test images from the mapbox/pixelmatch repository):

$ pixelmatch 1a.png 1b.png -o diff.png
Mismatched pixels: 106

The CLI exits with code 0 if images match and 1 if they differ (i.e., one or more mismatched pixels).

Library Usage

from pixelmatch import pixelmatch

# Compare two images and get mismatch count
num_diff = pixelmatch(
    "image1.png",
    "image2.png",
    output="diff.png",  # Optional: save diff image
)

print(f"Found {num_diff} mismatched pixels")

Arguments

  • img1, img2 — Image paths (str or Path) or PIL Image objects to compare. Note: image dimensions must be equal.
  • output — Image output for the diff. Can be a file path (str or Path) to save as PNG, a PIL Image object to fill with diff data, or None if diff output is not needed.
  • threshold — Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. 0.1 by default.
  • includeAA — Whether to count anti-aliased pixels as different. False by default.
  • alpha — Blending factor of unchanged pixels in the diff output. Ranges from 0 for pure white to 1 for original brightness. 0.1 by default.
  • aa_color — Tuple of (R, G, B) color for anti-aliased pixels in diff output. (255, 255, 0) (yellow) by default.
  • diff_color — Tuple of (R, G, B) color for different pixels in diff output. (255, 0, 0) (red) by default.
  • diff_color_alt — Tuple of (R, G, B) for an alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. If not provided, all differing pixels use diff_color.
  • diff_mask — Draw the diff over a transparent background (a mask), rather than over the original image. False by default.

Development

Install with dev dependencies (pytest, ruff):

pip install -e .[dev]

Run tests:

pytest tests/

Run tests with coverage (disables numba JIT compilation):

NUMBA_DISABLE_JIT=1 pytest tests/ --cov

Check code quality:

ruff check
ruff format --check
mypy .

Install pre-commit hook (runs ruff & mypy automatically before commits):

cp hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

The CI workflow automatically runs tests both with and without numba enabled, ensuring both the optimized and fallback code paths are tested.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pixelmatch_fast-1.3.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pixelmatch_fast-1.3.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file pixelmatch_fast-1.3.0.tar.gz.

File metadata

  • Download URL: pixelmatch_fast-1.3.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pixelmatch_fast-1.3.0.tar.gz
Algorithm Hash digest
SHA256 ef390bdda05218915e048d105926e4959ec578d003b795d746a83783de154bc3
MD5 f084beac5e67909667687c1653be8e78
BLAKE2b-256 685f010ebc4bab8855e006965fd1d5597f10009658ce54ad7f7cbbc32d6f3aa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixelmatch_fast-1.3.0.tar.gz:

Publisher: pypi-publish.yml on JustusRijke/pixelmatch-fast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixelmatch_fast-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pixelmatch_fast-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0510819f3f8e35c6af8f913930ec5da1ff8cd63a5bd3284f316c70c9d48a2c65
MD5 bdb84e6aa9d5579c4248b85df0ad411a
BLAKE2b-256 71839c10d3c2ef475e5f19156d7bd36e548e0e4fa239ec91985eda71986f9120

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixelmatch_fast-1.3.0-py3-none-any.whl:

Publisher: pypi-publish.yml on JustusRijke/pixelmatch-fast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page