Skip to content

fix(nodes): read the real alpha channel in Mask from Alpha - #10173

Open
MohammadHijjawi97 wants to merge 2 commits into
invoke-ai:mainfrom
MohammadHijjawi97:fix/mask-from-alpha-opaque-images
Open

MohammadHijjawi97 wants to merge 2 commits into
invoke-ai:mainfrom
MohammadHijjawi97:fix/mask-from-alpha-opaque-images

Conversation

@MohammadHijjawi97

@MohammadHijjawi97 MohammadHijjawi97 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Mask from Alpha took the image's last band as the mask. For an image without an alpha channel that is not alpha: it is the blue channel for RGB, the gray values for L, and palette indices for P (the saved "mask" is then even a P-mode image). The node now converts to RGBA and reads the A channel, so an opaque image gives a solid white mask and palette transparency is honored. RGBA/LA input is unchanged.

Before (RGB pixels red, green, dark blue): mask [0, 0, 64]
After: mask [255, 255, 255]

Related Issues / Discussions

None.

QA Instructions

  • uv run --no-sync pytest tests/app/invocations/test_image.py: 20 passed. Without the fix, the RGB case returns [0, 0, 64] and the palette case saves a P-mode image.
  • uv run --no-sync pytest tests/app/invocations/test_image_manipulation_invocations.py tests/app/invocations/test_mask_bounding_box.py: passed.
  • uv tool run ruff@0.11.2 check / format --check on the changed files: clean.

Review

The node's fields and version are unchanged.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Meaningful regression coverage added / updated where needed; obsolete tests/code removed
  • Persisted-state and API changes include required migrations / compatibility validation
  • Relevant performance/efficiency opportunities considered; material claims have evidence
  • Material review findings resolved and relevant checks rerun
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Mask from Alpha took the image's last band, which for an image without
alpha is the blue channel (RGB), the gray channel (L) or palette indices
(P). Convert to RGBA first, so opaque images give a solid mask and
palette transparency is honored.
@github-actions github-actions Bot added python PRs that change python files invocations PRs that change invocations python-tests PRs that change python tests labels Nov 5, 2026
@lstein lstein added the 7.0.1 label Nov 8, 2026
@lstein lstein moved this to 7.0.1: bugfixes and small features in Invoke - Community Roadmap Nov 8, 2026
@lstein lstein added 7.0.0 and removed 7.0.1 labels Nov 9, 2026
@JPPhoto
JPPhoto self-requested a review November 9, 2026 20:07

@JPPhoto JPPhoto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohammadHijjawi97 Thanks for the submission.

Findings/issues:

  • invokeai/app/invocations/image.py:244: For RGB/L/P inputs, tomask now returns opaque pixels instead of the previous last-band values, but its decorator at image.py:233 remains version 1.2.2. Saved workflows with that version appear current in webv2 (invokeai/frontend/webv2/src/features/workflow/core/document.ts:431), so users get no update warning as their masks change. A version bump is required when a node's functionality, inputs, or outputs change substantially; in this case, a minor version bump is acceptable to serve as an alert to users. This does not need an additional test.

@JPPhoto JPPhoto moved this from 7.0.1: bugfixes and small features to 7.0.0: UX overhaul in Invoke - Community Roadmap Nov 9, 2026
The node now returns an opaque mask for images without an alpha channel
instead of their last band, so saved workflows should be flagged as
using an older version.
@MohammadHijjawi97

Copy link
Copy Markdown
Contributor Author

@JPPhoto thanks for the review. I bumped tomask to 1.3.0 in the decorator and in invokeai/frontend/api/openapi.json, so saved workflows using 1.2.2 now get the update warning (commit 061f8ff).

@JPPhoto JPPhoto left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohammadHijjawi97 One case that I think this needs to preserve original behavior for is input mode 'L' (not 'LA') images. The mask in that case should be treated as before rather than using the alpha channel; that was the original intent of the node, IIRC, and your changes break it. You can confirm this by looking at the workflow builders in invokeai/frontend/webv2.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0.0 invocations PRs that change invocations python PRs that change python files python-tests PRs that change python tests

Projects

Status: 7.0.0: UX overhaul

Development

Successfully merging this pull request may close these issues.

3 participants