Skip to content

Can you please explain what threshold means? #155

Description

@gladykov

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 ?

Activity

  1. jhned commented on Aug 18, 2025

    @jhned

    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();
    }
  2. mourner commented on Oct 6, 2026

    @mourner
    Member

    Clarified this in the readme:

    How different two colors must be for a pixel to count as mismatched, from 0 to 1. It's a per-pixel perceptual color difference, where 1 is the difference between black and white, not a share of the image; to allow some percentage of the image to differ, compare the returned count against width * height instead. Smaller values make the comparison more sensitive. 0.1 by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions