BlazeDiff vs OpenCV
The blazediff Python wheel is ~3.4x faster
than reading two files with OpenCV and running cv2.absdiff, and it answers the
question a visual test asks: how many pixels differ, and where. OpenCV gives you
a difference array, and the counting, thresholding and anti-aliasing handling are
up to you.
cv2.absdiff subtracts two arrays per channel and returns the absolute values.
That is a building block, not a test assertion: it has no perceptual threshold
and no anti-aliasing detection, so one-pixel font rendering changes count as
differences. blazediff.compare decodes both files, runs a YIQ color delta with
optional anti-aliasing detection, and can write a diff image.
At a glance
OpenCV (opencv-python) | BlazeDiff (blazediff) | |
|---|---|---|
| License | Apache-2.0 (wheels bundle LGPL FFmpeg and Qt) | MIT |
| Dependencies | numpy | None |
| Input | numpy arrays, after cv2.imread | File paths (PNG, JPEG, QOI) |
| Output | Per-channel difference array | match, diff_count, diff_percentage, diff image |
| Perceptual threshold | No, you threshold the array | Yes, YIQ delta with threshold |
| Anti-aliasing | No | Optional detection |
| Scope | Full computer vision library | Image diffing |
Benchmarks
The OpenCV side reads both files as grayscale, runs cv2.absdiff, and counts the
non-zero pixels. The BlazeDiff side reads both files in color and runs
compare. Decode is included for both.
vs opencv-python (cv2.absdiff)
TOTAL TIME Β· 34 FIXTURES Β· MEAN OF 25 RUNS Β· IO INCLUDED
| # | Library | Version | Total time | vs OpenCV absdiff |
|---|---|---|---|---|
| 1 | BlazeDiff | 7.0.0 | 2.20s | 3.42x faster |
| 2 | OpenCV absdiff | 4.13.0.92 | 7.53s | baseline |
Per-fixture results (34)
| Fixture | OpenCV absdiff | BlazeDiff | BlazeDiff vs OpenCV absdiff |
|---|---|---|---|
| 4k/1 | 617ms | 213ms | 2.90x |
| 4k/1 (identical) | 782ms | 199ms | 3.92x |
| 4k/2 | 710ms | 280ms | 2.54x |
| 4k/2 (identical) | 695ms | 242ms | 2.88x |
| 4k/3 | 820ms | 270ms | 3.03x |
| 4k/3 (identical) | 790ms | 250ms | 3.16x |
| blazediff/1 | 4.94ms | 1.13ms | 4.38x |
| blazediff/1 (identical) | 4.50ms | 1.03ms | 4.36x |
| blazediff/2 | 4.14ms | 1.58ms | 2.61x |
| blazediff/2 (identical) | 4.01ms | 1.13ms | 3.55x |
| blazediff/3 | 44.59ms | 19.03ms | 2.34x |
| blazediff/3 (identical) | 44.49ms | 15.52ms | 2.87x |
| blazediff/4 | 30.53ms | 5.81ms | 5.26x |
| blazediff/4 (identical) | 30.23ms | 4.92ms | 6.15x |
| page/1 | 1.06s | 285ms | 3.72x |
| page/1 (identical) | 1.21s | 266ms | 4.52x |
| page/2 | 306ms | 73.36ms | 4.16x |
| page/2 (identical) | 288ms | 48.83ms | 5.91x |
| pixelmatch/1 | 3.46ms | 1.29ms | 2.68x |
| pixelmatch/1 (identical) | 4.40ms | 1.20ms | 3.65x |
| pixelmatch/2 | 1.16ms | 1.58ms | 0.73x |
| pixelmatch/2 (identical) | 1.07ms | 0.54ms | 2.00x |
| pixelmatch/3 | 3.40ms | 1.05ms | 3.23x |
| pixelmatch/3 (identical) | 3.96ms | 1.05ms | 3.76x |
| pixelmatch/4 | 7.76ms | 4.53ms | 1.71x |
| pixelmatch/4 (identical) | 6.00ms | 2.28ms | 2.63x |
| pixelmatch/5 | 1.84ms | 0.66ms | 2.78x |
| pixelmatch/5 (identical) | 1.89ms | 0.62ms | 3.05x |
| pixelmatch/6 | 2.64ms | 1.64ms | 1.61x |
| pixelmatch/6 (identical) | 4.48ms | 0.86ms | 5.21x |
| pixelmatch/7 | 1.89ms | 1.11ms | 1.70x |
| pixelmatch/7 (identical) | 2.06ms | 0.71ms | 2.90x |
| same/1 | 18.29ms | 3.55ms | 5.15x |
| same/1 (identical) | 19.38ms | 3.55ms | 5.46x |
| TOTAL | 7.53s | 2.20s | 3.42x |
pnpm benchmark python-opencv Β· Apple M1 Max Β· darwin/arm64 Β· Node v22.14.0 Β· rustc 1.97.1 (8bab26f4f 2026-07-14) Β· Python 3.11.14 Β· 2026-11-11 Β· eafe393-dirty
Switching
# Before
import cv2
import numpy as np
a = cv2.imread("baseline.png", cv2.IMREAD_GRAYSCALE)
b = cv2.imread("current.png", cv2.IMREAD_GRAYSCALE)
changed = np.count_nonzero(cv2.absdiff(a, b))
# After
from blazediff import diff
result = diff("baseline.png", "current.png", "diff.png", threshold=0.1)
if result.kind == "compared" and not result.identical:
print(f"{result.count} pixels differ")diff returns kind == "dimension-mismatch" when the two images differ in
size, where cv2.absdiff raises an error.
When to keep OpenCV
- The diff is one step in a larger vision pipeline: alignment, contours, morphology or feature matching.
- You need formats that only OpenCV reads, such as TIFF, WebP or HDR.
- You need GPU processing.
Related
- Python API
- BlazeDiff vs pixelmatch, which covers the PyPI pixelmatch port
- Image difference analysis for regions instead of a count
- All benchmarks