Skip to content

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