Repository navigation
Conversation
Port upstream pixelmatch v8's ignoreMask (mapbox/pixelmatch#171): pixels whose mask value is non-zero are skipped from the comparison and drawn as unchanged in the diff output, and differences that fall only inside the mask take the identical-images fast path. pixelmatch.core accepts one value per pixel; pixelmatch.contrib.PIL also accepts a PIL.Image of the same size, converted to grayscale. Closes whtsky#256
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Requested by winshyon · project thread
Description
This ports upstream pixelmatch v8's
ignoreMask(mapbox/pixelmatch#171) asignore_mask, following the acceptance criteria in the issue. It behaves like upstream:pixelmatch.core.pixelmatch(..., ignore_mask=...): takes one value per pixel (width * heightlong, e.g.list[int]orbytes). Pixels with a non-zero value are not compared. They are drawn as unchanged (the grayscale background) in the diff output, and they don't count towards the mismatch or triggerfail_fast. A mask of the wrong length raisesValueError.0and draws the grayscale background). This matches the!ignoreMask || !ignoreMask[i]check in upstream's identical loop.pixelmatch.contrib.PIL.pixelmatch(..., ignore_mask=...): accepts either aPIL.Imageof the same size or a sequence. The image is converted to"L", so any non-black pixel is ignored, and mode"1","L"and RGB masks all work. A size mismatch raisesValueError.Tests in
test_pixelmatch.py:1a/1bfixtures: the top half is masked, as in upstream's test. The mismatch equals the number of diff pixels in the unmasked half of the unmasked run. Masked pixels are drawn exactly like an unchanged image, and unmasked pixels are drawn exactly as without a mask.fail_fastcall, and the output equals the identical-image output."1"and mode"L"masks give the same count and output as core.I didn't touch the Changelog section of the README since entries there link the PR number; happy to add one if you'd like.
Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to help projects with open issues. The change was prepared with Claude Code and verified as listed below. If it doesn't fit, isn't up to your bar, or you'd simply rather not take it, please feel free to close it, no hard feelings at all 🙂
Related issue
Closes #256
Checklist
pytest --mypy --cov=pixelmatch --cov-report term-missing --benchmark-disablegives 51 passed and mypy is clean. The only uncovered lines are the existing image-size checks incore.py.black --check .is clean.CHANGELOG(README section): not updated, see above🤖 Generated with Claude Code