pixelmatch
pixelmatch copied to clipboard
Can you please explain what threshold means?
Hi!
Thank for your nice utility! Can you please explain what threshold means ? Is it like 10% of difference ignored when it is 0.1, and 100% when it is set to 1 ?
I checked the source and it looks like threshold is the amount that one pixel can be different from another pixel. If it's over the threshold, it's a different pixel and added to the number of different pixels.
If you want to stay within a certain ratio, take the number of different pixels and compare it against the total pixel area, kind of like this:
const numDiffPixels = pixelmatch(
img1.data,
img2.data,
diff.data,
img1.width,
img1.height,
{ threshold: 0.4 } // Adjust sensitivity here
);
const pixelArea = img1.width * img1.height;
const maxDiffPixelsByRatio = pixelArea * 0.4;
if (numDiffPixels > maxDiffPixelsByRatio) {
yellAboutIt();
}