Skip to main content

A C++17 port of the JavaScript pixelmatch library (with python binding), providing a small pixel-level image comparison library.

Project description

about python package

install

pip install pybind11-pixelmatch

diff image

pip install fire # for CLI
python3 -m pybind11_pixelmatch --help
python3 -m pybind11_pixelmatch data/pic1.png data/pic2.png diff_output.png
label image
img1
img2
diff

If you want a pure python package, then try pip install pixelmatch. But it's much slower.


pixelmatch-cpp17

Build Status License: ISC codecov

A C++17 port of the JavaScript pixelmatch library, providing a small pixel-level image comparison library.

Features accurate anti-aliased pixels detection and perceptual color difference metrics.

Based on mapbox/pixelmatch. pixelmatch-cpp17 is around 300 lines of code, and has no dependencies, operating on RGBA-encoded buffers.

pixelmatch::Options options;
options.threshold = 0.1f;

const std::vector<uint8_t> img1 = ...;
const std::vector<uint8_t> img2 = ...;
std::vector<uint8_t> diffImage(img1.size());

const int numDiffPixels = pixelmatch::pixelmatch(img1, img2, diffImage, width, height, stride, options);

Compared to mapbox/pixelmatch-cpp, pixelmatch-cpp17 ports the latest features from the JavaScript library, and is built with production-grade practices, including thorough test coverage and fuzz-testing. Build files are included for Bazel, but contributions for other build systems are welcome.

Implements ideas from the following papers:

Example output

expected actual diff
1diff
1diff
1diff

API

pixelmatch(img1, img2, output, width, height, strideInPixels[, options])

  • img1, img2 — Image data of the images to compare, as a RGBA-encoded byte array. Note: image dimensions must be equal.
  • output — Image data to write the diff to, or std::nullopt if you don't need a diff image.
  • width, height — Width and height of the images. Note that all three images need to have the same dimensions.
  • strideInPixels — Stride of the images. Note that all three images need to have the same stride.
  • options is a struct with the following fields:
    • threshold — Matching threshold, ranges from 0.0f to 1.0f. Smaller values make the comparison more sensitive. 0.1 by default.
    • includeAA — If true, disables detecting and ignoring anti-aliased pixels. 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.
    • aaColor — The color of anti-aliased pixels in the diff output as an RGBA color. (255, 255, 0, 255) by default.
    • diffColor — The color of differing pixels in the diff output as an RGBA color (255, 0, 0, 255) by default.
    • diffColorAlt — An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. If not provided, all differing pixels use the color specified by diffColor. std::nullopt by default.
    • diffMask — Draw the diff over a transparent background (a mask), rather than over the original image. Will not draw anti-aliased pixels (if detected).

Compares two images, writes the output diff and returns the number of mismatched pixels.

Usage

Bazel

Add the following to your WORKSPACE file:

git_repository(
    name = "pixelmatch-cpp17",
    branch = "main",
    remote = "https://github.com/jwmcglynn/pixelmatch-cpp17",
)

Then add a dependency on @pixelmatch-cpp17:

cc_test(
    name = "my_test",
    # ...
    data = glob([
      "testdata/*.png",
    ]),
    deps = [
        "@pixelmatch-cpp17",
        # ...
    ],
)

In your test file, include pixelmatch with:

#include <pixelmatch/pixelmatch.h>

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

pybind11_pixelmatch-0.1.2.tar.gz (4.8 MB view hashes)

Uploaded Source

Built Distributions

pybind11_pixelmatch-0.1.2-pp310-pypy310_pp73-win_amd64.whl (86.6 kB view hashes)

Uploaded PyPy Windows x86-64

pybind11_pixelmatch-0.1.2-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (119.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-pp39-pypy39_pp73-win_amd64.whl (86.6 kB view hashes)

Uploaded PyPy Windows x86-64

pybind11_pixelmatch-0.1.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (119.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-pp38-pypy38_pp73-win_amd64.whl (86.7 kB view hashes)

Uploaded PyPy Windows x86-64

pybind11_pixelmatch-0.1.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (119.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-pp37-pypy37_pp73-win_amd64.whl (86.5 kB view hashes)

Uploaded PyPy Windows x86-64

pybind11_pixelmatch-0.1.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (119.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-cp312-cp312-win_arm64.whl (78.3 kB view hashes)

Uploaded CPython 3.12 Windows ARM64

pybind11_pixelmatch-0.1.2-cp312-cp312-win_amd64.whl (87.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pybind11_pixelmatch-0.1.2-cp312-cp312-win32.whl (73.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

pybind11_pixelmatch-0.1.2-cp312-cp312-musllinux_1_1_x86_64.whl (636.2 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

pybind11_pixelmatch-0.1.2-cp312-cp312-musllinux_1_1_i686.whl (697.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

pybind11_pixelmatch-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (113.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (120.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-cp312-cp312-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl (160.4 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64 macOS 11.0+ universal2 (ARM64, x86-64)

pybind11_pixelmatch-0.1.2-cp311-cp311-win_arm64.whl (79.7 kB view hashes)

Uploaded CPython 3.11 Windows ARM64

pybind11_pixelmatch-0.1.2-cp311-cp311-win_amd64.whl (88.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pybind11_pixelmatch-0.1.2-cp311-cp311-win32.whl (74.0 kB view hashes)

Uploaded CPython 3.11 Windows x86

pybind11_pixelmatch-0.1.2-cp311-cp311-musllinux_1_1_x86_64.whl (636.8 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pybind11_pixelmatch-0.1.2-cp311-cp311-musllinux_1_1_i686.whl (697.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

pybind11_pixelmatch-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (121.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-cp311-cp311-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl (163.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64 macOS 11.0+ universal2 (ARM64, x86-64)

pybind11_pixelmatch-0.1.2-cp310-cp310-win_arm64.whl (78.6 kB view hashes)

Uploaded CPython 3.10 Windows ARM64

pybind11_pixelmatch-0.1.2-cp310-cp310-win_amd64.whl (87.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pybind11_pixelmatch-0.1.2-cp310-cp310-win32.whl (72.7 kB view hashes)

Uploaded CPython 3.10 Windows x86

pybind11_pixelmatch-0.1.2-cp310-cp310-musllinux_1_1_x86_64.whl (635.5 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pybind11_pixelmatch-0.1.2-cp310-cp310-musllinux_1_1_i686.whl (696.2 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pybind11_pixelmatch-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (120.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-cp310-cp310-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl (160.8 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64 macOS 11.0+ universal2 (ARM64, x86-64)

pybind11_pixelmatch-0.1.2-cp39-cp39-win_arm64.whl (78.7 kB view hashes)

Uploaded CPython 3.9 Windows ARM64

pybind11_pixelmatch-0.1.2-cp39-cp39-win_amd64.whl (85.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pybind11_pixelmatch-0.1.2-cp39-cp39-win32.whl (72.8 kB view hashes)

Uploaded CPython 3.9 Windows x86

pybind11_pixelmatch-0.1.2-cp39-cp39-musllinux_1_1_x86_64.whl (635.7 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pybind11_pixelmatch-0.1.2-cp39-cp39-musllinux_1_1_i686.whl (696.4 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pybind11_pixelmatch-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (120.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-cp39-cp39-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl (161.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64 macOS 11.0+ universal2 (ARM64, x86-64)

pybind11_pixelmatch-0.1.2-cp38-cp38-win_amd64.whl (87.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pybind11_pixelmatch-0.1.2-cp38-cp38-win32.whl (72.7 kB view hashes)

Uploaded CPython 3.8 Windows x86

pybind11_pixelmatch-0.1.2-cp38-cp38-musllinux_1_1_x86_64.whl (635.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pybind11_pixelmatch-0.1.2-cp38-cp38-musllinux_1_1_i686.whl (696.0 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pybind11_pixelmatch-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (112.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (119.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

pybind11_pixelmatch-0.1.2-cp38-cp38-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl (160.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64 macOS 11.0+ universal2 (ARM64, x86-64)

pybind11_pixelmatch-0.1.2-cp37-cp37m-win_amd64.whl (87.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

pybind11_pixelmatch-0.1.2-cp37-cp37m-win32.whl (74.4 kB view hashes)

Uploaded CPython 3.7m Windows x86

pybind11_pixelmatch-0.1.2-cp37-cp37m-musllinux_1_1_x86_64.whl (638.7 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pybind11_pixelmatch-0.1.2-cp37-cp37m-musllinux_1_1_i686.whl (699.9 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

pybind11_pixelmatch-0.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pybind11_pixelmatch-0.1.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (123.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

Supported by

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