Nodes/OmniNodes/Mask Morphology 🩹
ComfyUI Node

Mask Morphology 🩹

Grow, feather, or shrink a mask without opening an image editor

By TensorVizionΒ·Created 3 months agoΒ·Updated about 8 hours agoΒ· 0
Mask Morphology 🩹
  • mask
  • mask
  • summary
β—„operationβ–Ύβ–Ί
β—„amount8β–Ί

Hard-edged mask lines are where half of "why does my inpaint/composite look off" complaints start. A face-detect bbox ends exactly at the hairline, so when you composite or inpaint on it you get a clean rectangular cut through someone's hair. Mask Morphology 🩹 is the fix you reach for before the problem shows up: it grows, shrinks, feathers, or inverts a MASK tensor in one node, no image editor required.

It's part of the OmniNodes pack (TensorVizion), under TensorVizion/Image. It's a deliberately small node - one mask in, one mask out - and that's the point. ComfyUI already has masking everywhere (VAEEncodeForInpaint takes a mask, most compositing nodes take a mask), but nothing in core lets you fix the mask itself. This fills that gap.

How it works

The mask is just a single-channel float tensor, 0 to 1, and morphology is a classic image-processing move applied directly to it with PyTorch:

  • grow dilates the white area outward - implemented as repeated 3Γ—3 max-pool passes, each pass adding roughly a pixel of radius. amount is in pixels.
  • shrink is the inverse, repeated min-pool erosion.
  • feather gaussian-blurs the edge, turning a hard 0↔1 boundary into a gradient without changing the mask's overall size like grow/shrink do.
  • invert flips it (1 - mask) and ignores amount.

The repeated-small-kernel approach instead of one giant kernel keeps it fast on big masks and avoids the shape distortion a single huge kernel causes at borders. amount defaults to 8 and runs 0–200, which is plenty - I usually live in the 4–16 range.

The inputs that matter

Only three inputs: mask (the MASK you got from a detector, a hand-painted mask, or the "Convert to Mask" node), operation (the dropdown above), and amount. Outputs are the modified mask plus a summary string that tells you what it did - worth wiring into a text display when you're debugging, because a summary that says "Shrank mask by ~8px" beats squinting at previews.

Where people get burned: feathering after a grow that was too aggressive, or shrinking so far the mask disappears. The summary output shows the actual operation, and since amount can be 0, it's easy to dial back in.

Installing it

OmniNodes is one big pack, so you get this node by installing the whole thing:

cd ComfyUI/custom_nodes/
git clone https://github.com/TensorVizion/OmniNodes

Then restart ComfyUI. (ComfyUI Manager users: search "OmniNodes" in the Install Custom Nodes tab.) This node needs nothing extra - the Image category runs on PyTorch and NumPy, both already bundled with ComfyUI. Only the Web API category in this pack needs a pip install -r requirements.txt, and that's not this node. If it doesn't show up, restart fully and watch the terminal for [OmniNodes] lines: βœ… Loaded means it registered, ❌ Error importing means a traceback below it.

The standard recipe: detect a face, grow its mask ~6px so the composite edge lands in the hair instead of cutting it, then feather 8px so the blend doesn't show a seam. Inpainting gets the same treatment - a feathered mask is one of the cheapest quality wins in the masking-detection-detailing playbook.

CategoryTensorVizion/Image

Inputs (3)

NameTypeDefaultDescription
maskMASKβ€”
operationCOMBO4 options: grow, shrink, feather, invert
amountINT80–200β€”

Outputs (2)

NameTypeDescription
maskMASKβ€”
summarySTRINGβ€”