Add max and min operations to MaskComposite - #15335
Open
NubeBuster wants to merge 1 commit into
Open
Conversation
NubeBuster
requested review from
Kosinkadink,
alexisrolland,
comfyanonymous,
guill,
kijai and
rattus128
as code owners
August 5, 2026 23:23
Contributor
|
✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged. |
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Author
|
I have read and agree to the Contributor License Agreement |
comfy-legal
added a commit
to Comfy-Org/comfy-cla
that referenced
this pull request
Aug 5, 2026
NubeBuster
force-pushed
the
maskcomposite-max-min
branch
from
August 8, 2026 05:23
09252bd to
2a2969a
Compare
The and/or/xor operations round both masks to 0 or 1 before combining, so they discard feathering. There was previously no way to take the union or intersection of two soft masks without losing intermediate values. max and min are the standard fuzzy-set equivalents and preserve them. Also documents on the operation widget which ops are arithmetic and which binarize, since the distinction is not visible from the names. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
NubeBuster
force-pushed
the
maskcomposite-max-min
branch
from
August 9, 2026 00:40
2a2969a to
dfaaca1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MaskComposite'sand,orandxoroperations round both masks before combining:https://github.com/comfyanonymous/ComfyUI/blob/master/comfy_extras/nodes_mask.py#L290-L294
MASKis a float tensor in[0, 1], and much of the ecosystem exists to produce intermediate values (blur, feather, grow, segmentation confidence). But there is currently no operation on this node that takes the union or intersection of two soft masks without destroying that feathering.multiplygives a product-style intersection, andaddan approximate union, but neither is the standard union/intersection, and the three ops that are named like set operations all binarize.The failure is silent — the output is still a valid
MASK, so nothing complains, and the flattened feather only becomes visible much further downstream (e.g. as a hard seam in an inpaint composite).Change
Adds
maxandminto the operation list — the standard fuzzy-set union and intersection, which preserve intermediate values:Also adds a tooltip to the
operationwidget noting which operations are arithmetic and which binarize, since that distinction is not visible from the names alone.Compatibility
Non-breaking. Existing operations are untouched, and the new options are appended to the end of the list. Combo values are serialized by name, so saved workflows are unaffected.
Example
destination
[0.0, 0.25, 0.75, 1.0], source[0.5, 0.5, 0.5, 0.5]:max[0.5, 0.5, 0.75, 1.0]min[0.0, 0.25, 0.5, 0.5]or[0.0, 0.0, 1.0, 1.0]Tests
Adds
tests-unit/comfy_extras_test/nodes_mask_test.pycovering union/intersection semantics, preservation of intermediate values, commutativity and identity cases, plus one test documenting the existing binarizing behaviour ofor. 9 tests, all passing.🤖 Generated with Claude Code
PR Reviewed for being correct - Mark