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

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

Erode, dilate, and shape masks with audio-reactive kernels

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

Morphological operations are the classic OpenCV toolkit for reshaping a mask's edges - grow it, shrink it, clean up noise, close small gaps - and this node wraps the four standard ones (erode, dilate, open, close) with the pack's reactive layer on top. Static, it's a solid mask-cleanup tool. Fed a FEATURE, the kernel size or iteration count can pulse with audio or motion, so a mask can visibly breathe or grow spikier in time with a track instead of holding one fixed shape.

How it works

morph_type picks the operation: erode shrinks the mask's white regions (good for pulling edges in or removing small isolated specks), dilate grows them (good for filling small holes or thickening thin shapes), open is erode-then-dilate (removes small noise without shrinking the overall shape much), and close is dilate-then-erode (fills small gaps without growing the shape much). max_kernel_size sets how large the structuring element can get (odd numbers only, 3 to 21), and max_iterations sets how many times the operation repeats - both act as ceilings, since the actual kernel size and iteration count used on any given frame can be scaled down by the feature modulation described below.

feature_param chooses what the optional FEATURE input actually modulates: max_kernel_size, max_iterations, or None for no modulation at all (deterministic morph). feature_mode decides whether that modulation is relative - the feature nudges the value up and down around what you set - or absolute - the feature scales the value from zero up to your ceiling. feature_threshold gates when the modulation is allowed to apply at all, so a quiet passage in your audio feature can leave the mask untouched rather than morphing at the minimum setting.

Layered on top: invert flips the result, subtract_original removes a portion of the source mask from the output, grow_with_blur softens edges afterward, and mask_strength scales the whole effect.

Inputs and outputs

  • masks (required, MASK) - source mask or sequence.
  • morph_type - which operation runs.
  • max_kernel_size (default 5) and max_iterations (default 10) - how strong the operation can get.
  • opt_feature (optional, FEATURE) - connect to make kernel size or iterations react over time; leave empty for a fixed, deterministic morph.
  • Output - a single MASK.

Installing it

Install through ComfyUI Manager (search RyanOnTheInside) or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ryanontheinside/ComfyUI_RyanOnTheInside

Then pip install -r requirements.txt and restart ComfyUI. The morphological operations here run on OpenCV, which is part of the pack's standard dependency set - same install step covers it.

Common issues

max_kernel_size only accepts odd numbers by design (structuring elements need a defined center pixel) - if you're scripting values or copying settings from elsewhere, an even number will either get rejected or silently rounded, so stick to the odd steps the widget already enforces.

If feature modulation seems inert, check the same two things as elsewhere in the Flex family: feature_param set to None means the feature input is wired but not actually targeting anything, and feature_threshold set too high relative to your source feature means the modulation never crosses the gate. And as with the pack broadly - if the node fails to load at all, that's almost always a missing pip install -r requirements.txt, not this specific node.

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: - kernel_size: Dynamically adjust the size of the morphological operation - iterations: Dynamically adjust how many times the operation is applied - 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)
morph_typeCOMBOType of morphological operation ('erode', 'dilate', 'open', 'close')
max_kernel_sizeINT53–21Maximum size of the morphological kernel (3 to 21, odd numbers only)
max_iterationsINT101–50Maximum number of times to apply the operation (1 to 50)
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β€”