Nodes/NH-Nodes/Mask Morphology (NH)
ComfyUI Node

Mask Morphology (NH)

Expand masks by X and Y separately, fill holes, blur the edges

By jetthuangai·Created 5 months ago·Updated 21 days ago· 6
Mask Morphology (NH)
  • mask
  • MASK
horizontal_expand0
vertical_expand0
fill_holesfalse
blur_radius0.0

Every mask workflow eventually needs the mask tweaked: expanded so it covers the hair you missed, shrunk so it doesn't bleed onto the background, holes filled, edges feathered. Mask Morphology (NH) (class NH_MaskAdvancedMorphology) does all four in one node - and it's got one feature most morph nodes lack: independent horizontal and vertical expansion, which matters a lot more than you'd think.

How it works

Feed it a MASK and it applies four operations, all optional:

  • horizontal_expand / vertical_expand (integers, -512 to 512) - grow or shrink the mask along each axis separately. Positive expands, negative contracts. Because the axes are independent, you can widen a subject mask without making it taller, or grow it down without growing it up. A uniform morph node forces the same amount both ways; this one doesn't.
  • fill_holes (boolean) - closes interior holes, the classic "the mask has a gap where an eye should be solid" fix.
  • blur_radius (float, 0–100) - feathers the mask edge. Set it above zero and the hard boundary becomes a soft gradient, which is what you want before any inpainting so the seam doesn't scream.

The single output is the processed MASK, same size as the input.

Where you'd actually use it

Straight after any segmentation: garment masks, portrait masks, bbox-derived masks - the detectors in the masking/detailing world are notoriously stingy with coverage, and this is the "give it a bit more" node. In the NH pack it's the companion to Garment Segment (NH) and Portrait Segment (NH), which ship their own mask cleanup but this is the general-purpose one. The blur alone earns its place: it replaces the three-node "mask → blur → re-normalize" chain ComfyUI core makes you build.

Installing

ComfyUI Manager → search NH-Nodes → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt

Restart and refresh the browser page. numpy/scipy/scikit-image from the pack requirements cover this; nothing heavy.

Gotchas

Defaults are all zero/off, so it's a no-op until you set something - don't expect a surprise transform. Expansion values are in pixels at the mask's resolution; if you're working on a 2K mask, expanding by 4 pixels is invisible, so scale your numbers to the image. And there's no separate "both axes same amount" shortcut - set both fields or one axis stays put, which is exactly the trap if you forget vertical_expand. Also worth noting: on a very soft (pre-blurred) mask, expansion behaves differently than on a hard binary mask, so order your operations - expand first, blur last, is the usual recipe.

CategoryNH-Nodes/Mask

Inputs (5)

NameTypeDefaultDescription
maskMASK
horizontal_expandINT0-512–512
vertical_expandINT0-512–512
fill_holesBOOLEANfalse
blur_radiusFLOAT0.00–100

Outputs (1)

NameTypeDescription
MASKMASK