Nodes/Mickmumpitz-Nodes/Mask Directional Extend
ComfyUI Node

Mask Directional Extend

Grow a mask in one direction without touching the others

By mickmumpitz·Created 8 months ago·Updated 9 days ago· 47
Mask Directional Extend
  • mask
  • mask
left0
right0
down0
up0
blur_px0

Mask Directional Extend is a mask utility from the Mickmumpitz pack that does one thing: expand a mask independently in each direction - left, right, up, down - with an optional feathered edge. Most mask-grow tools are uniform: they inflate a mask by N pixels all around. That's wrong for a lot of real jobs, because masks usually need to grow asymmetrically. The node's natural habitat is the pack's lipsync-for-LTX workflows, where you've detected the mouth region and want to widen the mask down toward the chin or up toward the nose - but not into the eyes - and PoseKeypointToMask gives you a tight mask that needs directional breathing room.

The use case in plain terms: you have a mouth mask from face landmarks, and you want the area the VFX applies to (or the area excluded from editing) to extend further in one direction. Uniform dilation would overshoot on the sides. This node lets you say "down 24px, everywhere else 0."

How it works

The mechanism is a per-axis max-pooling dilation. If left or right is set, the mask is padded horizontally and max-pooled with a kernel whose width is left + right + 1, which expands the white region outward by exactly those amounts. The same trick runs vertically for up/down. Because each axis runs independently, the extension amounts don't interfere - left+right don't have to match, up+down don't have to match, and you can extend only one side if you want. If blur_px is set, the result gets a double box-blur (avg-pool) to feather the newly extended edges so the mask fades out instead of ending in a hard line. Everything is clamped to 0–1 at the end, so the output is a clean, valid MASK.

The inputs and outputs

  • mask (MASK, required) - the input mask.
  • left, right, down, up - pixels to extend on each side (0–512, default 0). Set only the ones you need.
  • blur_px (default 0) - feather the extended edges with a box blur. Zero = hard edge.

The single output, mask, is the extended mask, same spatial size as the input - the extension happens inside the canvas, not by growing the canvas.

Installing it

Part of the Mickmumpitz pack - ComfyUI Manager, search "Mickmumpitz", install, restart:

cd ComfyUI/custom_nodes
git clone https://github.com/mickmumpitz/ComfyUI-Mickmumpitz-Nodes.git

Uses torch pooling ops plus the pack's opencv dependency; no models.

Common issues

The thing to remember: extension doesn't change the canvas size. A mask already touching the frame edge can't "extend" past it - pixels beyond the border simply stay beyond the border, which is usually what you want but occasionally surprises people who expected a larger output canvas. Also, since dilation is max-pooling based, it treats the mask as solid white where it's nonzero: a soft, semi-transparent mask gets treated as binary for the extension step, then feathered by blur_px afterward. If you need directional growth of a graduated mask, blur it first, extend, and accept the slight flattening - or just use blur_px to soften the result.

CategoryMickmumpitz/Lipsync

Inputs (6)

NameTypeDefaultDescription
maskMASK
leftINT00–512Extend mask leftward by this many pixels.
rightINT00–512Extend mask rightward by this many pixels.
downINT00–512Extend mask downward by this many pixels.
upINT00–512Extend mask upward by this many pixels.
blur_pxINT00–64Feather the extended edges with a box blur.

Outputs (1)

NameTypeDescription
maskMASK