Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect difference between white and transparent pixels #26

Open
tommypreger opened this issue Mar 24, 2017 · 8 comments
Open

Detect difference between white and transparent pixels #26

tommypreger opened this issue Mar 24, 2017 · 8 comments
Assignees
Labels

Comments

@tommypreger
Copy link

It seems like pixelmatch always returns 0 diff when comparing two images that only contain white pixels and transparency. I noticed this when trying to compare two white logo pngs. Pixelmatch doesn't care if i transform, rotate or draw more white on my logo, it still says 0 diff to the original. If I do the same experiment with a colored image it behaves as intended.

@tommypreger
Copy link
Author

It seems this is the same bug as #21. Can't tell from the discussions why that issue was closed...

@mourner
Copy link
Member

mourner commented Mar 27, 2017

Pixelmatch measures visual difference, not numeric one, so it blends all transparent/semi-transparent pixels over a white background. If you have transparent pixels mixed with white pixels on a white background, you won't see the difference, so neither does pixelmatch. Would it help to introduce an option to set a different default background to blend images to?

@tommypreger
Copy link
Author

Hi!
I'm not sure I understand how visual difference is measured, but it seems like being able to pick a non-solid background would help. Any non-white color would be better than white (since a lot of graphic/logo images are white), but all solid colors will obviously have a blind spot with that specific color. Is it possible to compare to a patterned background? Such as checker-box or something?

@tommypreger
Copy link
Author

Is this something that could be implemented? And would it have any speed-implications?
Pixelmap fits my needs perfectly except for this "bug", which renders it unusable for me.
A fix would be greatly appreciated! :)

@mourner
Copy link
Member

mourner commented Apr 7, 2017

Yes, I think a checkerboard-style background would be possible and likely not impacting speed — let's look into that! Maybe we should change the white blending color to gray as a first simple step though since it's less likely to go unnoticeable.

@tommypreger
Copy link
Author

tommypreger commented Apr 7, 2017

Okay, so I can't say I understand the inner workings of Pixelmap, but after messing around a little bit with the source I have managed to make it do what I want, i think.

// blend semi-transparent color
function blend(c, a) {
    var b = (c + 128) % 256;
    return b + (c - b) * a;
}

This is just an intuitive hack from my side, and I'm not sure if it has any unwanted side-effects.
Edit: it fails all tests, but it keeps working for me... I'll continue using this hack for now.

@tommypreger
Copy link
Author

Have you had time to try out my fix? :)

@sul4bh
Copy link

sul4bh commented May 23, 2017

Any updates on this?

@mourner mourner changed the title white images always has 0 diff Detect difference between white and transparent pixels Jun 6, 2019
@mourner mourner self-assigned this Jun 6, 2019
ReDrUm pushed a commit to ReDrUm/pixelmatch that referenced this issue Sep 20, 2019
…allow-for-custom-snapshots-dir to master

* commit 'cb529963b7f00c6c1be2a43bf4a7a815e611a0f0':
  fix(configureToMatchImageSnapshot): add ability to have common customSnapshotsDir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants