Flex Mask Math β‘π ‘π π £π
Combine two masks with add, subtract, multiply, min, or max
- masks
- mask_b
- opt_feature
- MASK
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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| strength | FLOAT | 1.000β1 | Overall strength of the feature modulation (0.0 to 1.0) |
| feature_threshold | FLOAT | 0.000β1 | Threshold for feature activation (0.0 to 1.0) |
| feature_param | COMBO | Choose which parameter to modulate: - max_blend: Dynamically adjust the blend between masks - None: No parameter modulation | |
| feature_mode | COMBO | relative | How to apply the feature modulation: - relative: Changes are centered around the original value - absolute: Changes scale directly from zero to the maximum |
| masks | MASK | Input mask or sequence of masks to be processed (MASK type) | |
| invert | BOOLEAN | false | When enabled, inverts the mask output (black becomes white and vice versa) |
| subtract_original | FLOAT | 0.000β1 | Amount of the original mask to subtract from the result (0.0 to 1.0) |
| grow_with_blur | FLOAT | 0.00β10 | Amount of Gaussian blur to apply for mask growth (0.0 to 10.0) |
| mask_strength | FLOAT | 1.000β1 | Overall strength of the mask effect (0.0 to 1.0) |
| mask_b | MASK | Second mask to combine with the input mask (MASK type) | |
| combination_method | COMBO | Mathematical operation to apply ('add', 'subtract', 'multiply', 'minimum', 'maximum') | |
| max_blend | FLOAT | 1.000β1 | Maximum blend factor between masks (0.0 to 1.0) |
| opt_featureopt | FEATURE | Optional 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)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | β |