Skip to content

Commit ab76f52

Browse files
committed
cleanup readme
1 parent bddb613 commit ab76f52

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

‎README.md‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@
66
A small, simple and fast JavaScript pixel-level **image comparison library**,
77
originally created to compare screenshots in tests.
88

9-
Features accurate **anti-aliased pixels detection** and **perceptual color difference** metrics.
10-
Inspired by [Resemble.js](https://github.com/Huddle/Resemble.js)
11-
and [Blink-diff](https://github.com/yahoo/blink-diff).
12-
Unlike these libraries, pixelmatch is just **a few hundred lines of code**,
13-
has **no dependencies**, and works on **raw typed arrays** of image data,
14-
so it's **very fast** and can be used in both Node and browsers.
9+
Features accurate **anti-aliased pixel detection** and a **perceptual color difference** metric.
10+
It's just **a few hundred lines of code**, has **no dependencies**, and works on **raw typed arrays**
11+
of image data, so it's **very fast** and runs in both Node and browsers.
12+
There's also an official [C++ port](https://github.com/mapbox/pixelmatch-cpp).
1513

1614
```js
1715
const numDiffPixels = pixelmatch(img1, img2, diff, 800, 600, {threshold: 0.1});
1816
```
1917

20-
Implements ideas from the following papers:
21-
22-
- [A perceptual color space for image processing](https://bottosson.github.io/posts/oklab/) (2020, Björn Ottosson) — the OKLab color space used for color difference.
23-
- [Distance metrics for very large color differences](https://onlinelibrary.wiley.com/doi/10.1002/col.22451) (2019, Saeideh Abasi et al.) — the OKLab HyAB metric used to compare colors.
24-
- [Anti-aliased pixel and intensity slope detector](https://www.researchgate.net/publication/234126755_Anti-aliased_Pixel_and_Intensity_Slope_Detector) (2009, Vytautas Vyšniauskas)
18+
Compares colors using the [OKLab color space](https://bottosson.github.io/posts/oklab/) (Björn Ottosson, 2020)
19+
and the [HyAB distance](https://onlinelibrary.wiley.com/doi/10.1002/col.22451) (Saeideh Abasi et al., 2019),
20+
and detects anti-aliasing with the [anti-aliased pixel and intensity slope detector](https://www.researchgate.net/publication/234126755_Anti-aliased_Pixel_and_Intensity_Slope_Detector)
21+
(Vytautas Vyšniauskas, 2009).
2522

2623
## [Demo](https://observablehq.com/@mourner/pixelmatch-demo)
2724

2825
## Example output
2926

3027
| expected | actual | diff |
3128
| --- | --- | --- |
32-
| ![](test/fixtures/4a.png) | ![](test/fixtures/4b.png) | ![1diff](test/fixtures/4diff.png) |
33-
| ![](test/fixtures/3a.png) | ![](test/fixtures/3b.png) | ![1diff](test/fixtures/3diff.png) |
34-
| ![](test/fixtures/6a.png) | ![](test/fixtures/6b.png) | ![1diff](test/fixtures/6diff.png) |
29+
| ![](test/fixtures/4a.png) | ![](test/fixtures/4b.png) | ![](test/fixtures/4diff.png) |
30+
| ![](test/fixtures/3a.png) | ![](test/fixtures/3b.png) | ![](test/fixtures/3diff.png) |
31+
| ![](test/fixtures/6a.png) | ![](test/fixtures/6b.png) | ![](test/fixtures/6diff.png) |
3532

3633
## API
3734

3835
### pixelmatch(img1, img2, output, width, height[, options])
3936

40-
- `img1`, `img2` — Image data of the images to compare (`Buffer`, `Uint8Array` or `Uint8ClampedArray`). **Note:** image dimensions must be equal.
41-
- `output` — Image data to write the diff to, or `null` if don't need a diff image.
42-
- `width`, `height` — Width and height of the images. Note that _all three images_ need to have the same dimensions.
37+
Compares two images, writes the output diff and returns the number of mismatched pixels (or the
38+
highest count in any window with `windowSize`).
39+
40+
- `img1`, `img2` — Image data of the images to compare (`Buffer`, `Uint8Array` or `Uint8ClampedArray`).
41+
- `output` — Image data to write the diff to, or `null` if you don't need a diff image.
42+
- `width`, `height` — Width and height of the images. **Note:** _all three images_ need to have the same dimensions.
4343

4444
`options` is an object literal with the following properties:
4545

@@ -49,13 +49,11 @@ Implements ideas from the following papers:
4949
- `aaColor` — The color of anti-aliased pixels in the diff output in `[R, G, B]` format. `[255, 255, 0]` by default.
5050
- `diffColor` — The color of differing pixels in the diff output in `[R, G, B]` format. `[255, 0, 0]` by default.
5151
- `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`. `null` by default.
52-
- `diffMask` — Draw the diff over a transparent background (a mask), rather than over the original image. Will not draw anti-aliased pixels (if detected).
52+
- `diffMask` — Draw the diff over a transparent background (a mask), rather than over the original image. Will not draw anti-aliased pixels (if detected). `false` by default.
5353
- `checkerboard` — Blend semi-transparent pixels against a checkerboard pattern when comparing (`true`) rather than plain white (`false`), avoiding false matches between colors that only look alike over one background. `true` by default.
5454
- `windowSize` — If set to a finite number `N`, return the maximum number of differing pixels in any `N`×`N` sliding window instead of the total count (see below). `Infinity` by default.
5555
- `ignoreMask` — A `Uint8Array`, `Uint8ClampedArray` or `Buffer` with one value per pixel (`width * height` long); pixels with a non-zero value are excluded from the comparison and drawn as unchanged in the diff output. Not set by default.
5656

57-
Compares two images, writes the output diff and returns the number of mismatched pixels.
58-
5957
### Windowed diff counts
6058

6159
Normally the return value is the total number of differing pixels. With `windowSize: N` you get the
@@ -81,9 +79,12 @@ window. The default `Infinity` makes the window the whole image, which is the to
8179
Pixelmatch comes with a binary that works with PNG images:
8280

8381
```bash
84-
pixelmatch image1.png image2.png output.png 0.1
82+
pixelmatch image1.png image2.png [diff.png] [threshold] [includeAA]
8583
```
8684

85+
It prints the number of different pixels and exits with code `0` if the images match, `66` if they
86+
differ, `65` if their dimensions don't match, and `64` on wrong usage.
87+
8788
## Example usage
8889

8990
### Node.js

0 commit comments

Comments
 (0)