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

Fix RGBA mask conversion in prepare_mask to preserve transparency #3079

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

IndigoDosSantos
Copy link

Previously, the prepare_mask function used a simple grayscale conversion (mask.convert("L")), which discarded the alpha channel in RGBA images. This resulted in fully transparent pixels being rendered as white, causing them to be mistakenly included in the mask. So, if the user uploaded a PNG mask with transparency in webui's inpaint upload tab, then enabling "Crop input image based on A1111 mask" did not crop at all, since everything was part of the mask.

This commit introduces a custom grayscale conversion that:

  • Computes the standard RGB luminance (using weights 0.299, 0.587, 0.114),
  • Multiplies the computed luminance by the normalized alpha channel, ensuring that:
    • Fully transparent pixels become pure black, • Partially transparent pixels have appropriately scaled grayscale values.

The rest of the function’s behavior (inverting and Gaussian blurring) remains unchanged, preserving the overall mask preparation logic for inpainting tasks.

This update ensures correct handling of PNG masks with transparent pixels by the "Crop input image based on A1111 mask" feature.

Previously, the prepare_mask function used a simple grayscale conversion (mask.convert("L")), which discarded the alpha channel in RGBA images. This resulted in fully transparent pixels being rendered as white, causing them to be mistakenly included in the mask. So, if the user uploaded a PNG mask with transparency in webui's inpaint upload tab, then enabling "Crop input image based on A1111 mask" did not crop at all, since everything was part of the mask.

This commit introduces a custom grayscale conversion that:
- Computes the standard RGB luminance (using weights 0.299, 0.587, 0.114),
- Multiplies the computed luminance by the normalized alpha channel,
ensuring that:
  • Fully transparent pixels become pure black,
  • Partially transparent pixels have appropriately scaled grayscale values.

The rest of the function’s behavior (inverting and Gaussian blurring) remains unchanged, preserving the overall mask preparation logic for inpainting tasks.

This update ensures correct handling of PNG masks with transparent pixels by the "Crop input image based on A1111 mask" feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant