-
Notifications
You must be signed in to change notification settings - Fork 606
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
Blur for images with alpha is incorrect, bleeds color from transparent pixels #2324
Comments
Wow, good catch! I think this is a general issue coming from |
I am not 100% certain this is the correct fix. I am not a blur expert and I may be missing something. It's probably worth researching this. Or, if you want a shortcut on the research, here's what ChatGPT says about it: https://chatgpt.com/share/66e8069d-6198-800f-8ca4-dfd8fb5360ae |
This StackOverflow answer seems to suggest the same thing, with the contributions being weighted by alpha naturally if the RBG values are multiplied by alpha first: https://computergraphics.stackexchange.com/a/5517 |
Yes, premultiplied alpha color space is the right answer here. |
With this test image the blur implementation shows artifacts:
blur-test-input
It's just a white rectangle in the middle, surrounded by fully transparent pixels.
Gaussian blur in
image
bleeds color from fully transparent pixels into the white rectangle, resulting in the following image:The fully transparent pixels have R set to 255 while all the other channels are set to 0, and that red color bleeds into the white rectangle.
The expected blur as produced by GIMP is like this - blurred white rectangle without any red color:
blurred-gimp-20px
To avoid such artifacts, the pixel's contribution to the color change should be weighted by its alpha channel value. Fully transparent pixels should get multiplied by 0 and not contribute to the changes in non-alpha channels at all.
Code used for testing:
Originally found in #2302 (comment), moving it to the issue tracker so that it doesn't get lost.
Tested on
image
from git on commit 98ceb71The text was updated successfully, but these errors were encountered: