Nodes/RyanOnTheInside/Flex Mask Math βš‘πŸ…‘πŸ…žπŸ…£πŸ…˜
ComfyUI Node

Flex Mask Math βš‘πŸ…‘πŸ…žπŸ…£πŸ…˜

Combine two masks with add, subtract, multiply, min, or max

By ryanontheinsideΒ·Created 2 years agoΒ·Updated 5 months agoΒ· 852
Flex Mask Math βš‘πŸ…‘πŸ…žπŸ…£πŸ…˜
  • masks
  • mask_b
  • opt_feature
  • MASK
β—„strength1.00β–Ί
β—„feature_threshold0.00β–Ί
β—„feature_paramβ–Ύβ–Ί
β—„feature_moderelativeβ–Ί
β—„invertfalseβ–Ί
β—„subtract_original0.00β–Ί
β—„grow_with_blur0.0β–Ί
β—„mask_strength1.00β–Ί
β—„combination_methodβ–Ύβ–Ί
β—„max_blend1.00β–Ί

Sometimes one mask isn't enough - you've got a subject mask from segmentation and a hand-painted region you want to intersect it with, or two reactive masks from different sources you want combined into one. Flex Mask Math is the node for that: it takes two masks and combines them with a plain mathematical operation, then runs the result through the same reactive post-processing every other Flex mask node in the pack shares.

How it works

combination_method picks the operation: add brightens the overlap (unions get brighter, up to full white), subtract removes mask_b's coverage from masks, multiply keeps only where both masks agree (a true intersection - anywhere either mask is black, the result is black), minimum takes the darker value at each pixel, and maximum takes the lighter one (effectively a union, similar to add but without values stacking past white). max_blend caps how much of the combination actually comes through - at 0 you'd get back close to the original masks input regardless of the operation, at 1 the full combined result. feature_param can target max_blend, so the strength of the combination itself can pulse with an audio or motion signal rather than sitting fixed.

Inputs and outputs that matter

  • masks / mask_b (required, MASK) - the two masks being combined.
  • combination_method - add, subtract, multiply, minimum, or maximum.
  • max_blend (default 1, 0–1) - how much of the combined result comes through.
  • opt_feature (optional, FEATURE) - make the blend strength reactive.
  • Output - a single MASK.

Installing it

Via ComfyUI Manager: search "RyanOnTheInside," install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ryanontheinside/ComfyUI_RyanOnTheInside.git
cd ComfyUI_RyanOnTheInside
pip install -r requirements.txt

then restart. No model downloads - it's per-pixel arithmetic between two masks you already have.

Common issues & troubleshooting

Result doesn't match the mask size you expected. Both masks and mask_b need to be the same resolution and frame count - a mismatch here behaves like any other dual-mask operation in ComfyUI and will either error or produce a broadcast result you didn't intend. Resize upstream first.

multiply gives you an almost-black mask. That's expected if the two masks don't overlap much - multiply is a true intersection, so two masks covering different parts of the frame will multiply down to close to nothing. If you actually wanted a union (either region counted), use maximum or add instead.

Picked the wrong operation for the goal. It's easy to reach for subtract when you actually want multiply, or vice versa - subtract removes one mask's coverage from the other regardless of overlap, while multiply only keeps the shared region. If the result looks inverted from what you expected, double-check which of those two you actually needed.

CategoryRyanOnTheInside/FlexFeatures/Targets/Masks

Inputs (13)

NameTypeDefaultDescription
strengthFLOAT1.000–1Overall strength of the feature modulation (0.0 to 1.0)
feature_thresholdFLOAT0.000–1Threshold for feature activation (0.0 to 1.0)
feature_paramCOMBOChoose which parameter to modulate: - max_blend: Dynamically adjust the blend between masks - None: No parameter modulation
feature_modeCOMBOrelativeHow to apply the feature modulation: - relative: Changes are centered around the original value - absolute: Changes scale directly from zero to the maximum
masksMASKInput mask or sequence of masks to be processed (MASK type)
invertBOOLEANfalseWhen enabled, inverts the mask output (black becomes white and vice versa)
subtract_originalFLOAT0.000–1Amount of the original mask to subtract from the result (0.0 to 1.0)
grow_with_blurFLOAT0.00–10Amount of Gaussian blur to apply for mask growth (0.0 to 10.0)
mask_strengthFLOAT1.000–1Overall strength of the mask effect (0.0 to 1.0)
mask_bMASKSecond mask to combine with the input mask (MASK type)
combination_methodCOMBOMathematical operation to apply ('add', 'subtract', 'multiply', 'minimum', 'maximum')
max_blendFLOAT1.000–1Maximum blend factor between masks (0.0 to 1.0)
opt_featureoptFEATUREOptional feature input for modulation Connect any feature node here to control the effect. Features can come from audio, motion, color, or other sources.

Outputs (1)

NameTypeDescription
MASKMASKβ€”