High-performance Python port of mapbox/pixelmatch for perceptual image comparison
Project description
pixelmatch-fast
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 Python (v3.10 or higher) and 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, orNoneif diff output is not needed.threshold— Matching threshold, ranges from0to1. Smaller values make the comparison more sensitive.0.1by default.includeAA— Whether to count anti-aliased pixels as different.Falseby default.alpha— Blending factor of unchanged pixels in the diff output. Ranges from0for pure white to1for original brightness.0.1by 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 usediff_color.diff_mask— Draw the diff over a transparent background (a mask), rather than over the original image.Falseby default.
Development
Install uv. Then, install dependencies & activate the automatically generated virtual environment:
uv sync --locked
source .venv/bin/activate
Skip --locked to use the newest dependencies (this might modify uv.lock)
Run tests:
pytest
Run tests with coverage (disables numba JIT compilation):
NUMBA_DISABLE_JIT=1 pytest --cov
Check code quality:
ruff check
ruff format --check
ty check
Better yet, install the pre-commit hook, which runs code quality checks before every commit:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pixelmatch_fast-1.3.1.tar.gz.
File metadata
- Download URL: pixelmatch_fast-1.3.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d204d3cce4a9a8fd131c0983ffd5ae2e49571f5bf62b34fff337b9f57e9445bc
|
|
| MD5 |
3a903fbc5bb165189f4ae0ffd45b96ba
|
|
| BLAKE2b-256 |
d040ed9fe06f5a3856913f3ebfc0cce9833ab518b3ad29bfbe00840502659101
|
Provenance
The following attestation bundles were made for pixelmatch_fast-1.3.1.tar.gz:
Publisher:
pypi-publish.yml on JustusRijke/pixelmatch-fast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pixelmatch_fast-1.3.1.tar.gz -
Subject digest:
d204d3cce4a9a8fd131c0983ffd5ae2e49571f5bf62b34fff337b9f57e9445bc - Sigstore transparency entry: 790778584
- Sigstore integration time:
-
Permalink:
JustusRijke/pixelmatch-fast@a8e6109040f1b36dbb63eee3e15a3bd2cb6651fe -
Branch / Tag:
refs/tags/1.3.1 - Owner: https://github.com/JustusRijke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@a8e6109040f1b36dbb63eee3e15a3bd2cb6651fe -
Trigger Event:
release
-
Statement type:
File details
Details for the file pixelmatch_fast-1.3.1-py3-none-any.whl.
File metadata
- Download URL: pixelmatch_fast-1.3.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bccb443868e02cec7884152ab68b1e371746597e8c7912543de0f9dd789c9c4
|
|
| MD5 |
0de4687d35731ef5f5fd3d1ce86817f1
|
|
| BLAKE2b-256 |
555593ec89aad51bbc71248599c949ca1dcf7bae308b0f52a8490418e4326be7
|
Provenance
The following attestation bundles were made for pixelmatch_fast-1.3.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on JustusRijke/pixelmatch-fast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pixelmatch_fast-1.3.1-py3-none-any.whl -
Subject digest:
1bccb443868e02cec7884152ab68b1e371746597e8c7912543de0f9dd789c9c4 - Sigstore transparency entry: 790778587
- Sigstore integration time:
-
Permalink:
JustusRijke/pixelmatch-fast@a8e6109040f1b36dbb63eee3e15a3bd2cb6651fe -
Branch / Tag:
refs/tags/1.3.1 - Owner: https://github.com/JustusRijke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@a8e6109040f1b36dbb63eee3e15a3bd2cb6651fe -
Trigger Event:
release
-
Statement type: