Nodes/ComfyTV/Matte Morphology
ComfyUI Node

Matte Morphology

Matte Morphology fixes what the keyer can't

By jtydhr88·Created 3 months ago·Updated about 15 hours ago· 725
Matte Morphology
  • video
  • video
force_run_token0
project_id
parent_output_id0
operode
size_x1
size_y1

Matte Morphology is the cleanup crew of ComfyTV's keying chain. Your keyer hands you a matte with jagged edges, a few stray specks, and hair-thin semi-transparent fringes; this stage chokes it back or spreads it out using classic morphology operators until the edges are actually clean. It's the difference between a key that's "sort of working" and one that survives being composited over a moving background.

ComfyTV is the canvas-style app layer on ComfyUI where every operation is its own node. In the keying flow (Keyer → Matte Morphology → Key Mix) this is the "clean the matte" step, and it's deliberately positioned between pulling the key and compositing it - the order matters.

How it works. It runs morphological operators on the matte, per frame, on your GPU. Four operations cover the cases:

  • erode - shrink the matte (choke). Kills the semi-transparent fringe and spill halo at the subject's edge, at the cost of a slightly smaller subject.
  • dilate - grow the matte (spread). Fills in skimpy edges and lets you regain area after an erode.
  • open - erode then dilate. Removes small specks and islands while keeping the main region's size.
  • close - dilate then erode. Fills small holes and gaps while keeping the main region's size.

size_x / size_y control the kernel size in pixels (0–64) - how many pixels you erode, dilate, or clean. Non-square kernels are occasionally useful, but 1–3 pixels symmetric is the usual zone for fringe cleanup.

The inputs that matter. The force_run_token, project_id and parent_output_id inputs are internal plumbing. The real set is small:

  • video - the matte to clean (required).
  • op - erode / dilate / open / close.
  • size_x / size_y - kernel size per axis, 0–64.

Output is a video - the cleaned matte, ready for Key Mix.

Install. Install the pack once:

cd ComfyUI/custom_nodes
git clone https://github.com/jtydhr88/ComfyTV

Restart ComfyUI (full restart, not a browser refresh) and the stage appears under ComfyTV → Keying. ComfyUI Manager - search "ComfyTV" - works too. Zero Python dependencies (the pack's pyproject.toml dependency list is empty) and no model files - pure per-frame morphology. Desktop/multi-install users: clone into the running instance's path from the startup log or the node won't register.

Where people get burned. Overdoing the kernel size. A size of 5+ erodes a real chunk of your subject - chins and hairlines vanish - and no amount of downstream fixing brings them back. Work in 1–2px steps and check against the Matte Monitor. Second: the order of operations genuinely matters; open (specks) before you consider erode (fringe), and if you choke with erode you should usually follow with a small dilate to recover the edge you just ate - doing it in one pass here means wiring two stages, which is fine and normal. And remember this operates on the matte video only: if you feed it the full-color composite instead of the alpha, you'll get garbage. When the edges still look crunchy after cleaning, the real fix is upstream - soften the key's edge with the Keyer's softness rather than beating on the morphology.

CategoryComfyTV/Keying

Inputs (7)

NameTypeDefaultDescription
force_run_tokenINT00–2147483647Internal — bumped on Run to invalidate ComfyUI's input cache.
project_idSTRINGInternal — populated by the projectStore on the frontend.
parent_output_idINT00–2147483647Internal — lineage parent set by spawn handlers on the frontend.
opCOMBOerode4 options: erode, dilate, open, close
size_xINT10–64
size_yINT10–64
videooptCOMFYTV_VIDEO

Outputs (1)

NameTypeDescription
videoCOMFYTV_VIDEO