Directional Mask Expand
Poke a mask toward one side — Directional Mask Expand explained
- mask
- MASK
Most mask nodes grow or shrink a mask in every direction at once. Directional Mask Expand is the one case where that's wrong: you need the mask to reach out toward one specific edge. It's a one-trick node from the tiny ComfyUI-MaskMorph pack, and if the trick fits your problem it beats fiddling with a dozen other nodes.
Think of the real uses: your text-grounded mask from a bounding box ends up tighter than you'd like (people pad those boxes ~50px for a reason - see the inpainting writeups), but you only want padding toward the canvas edge, not a uniform grow that eats into the subject. Or you've got a detection mask that stops just short of a shadow or reflection you want included, and you need it extended in exactly one direction. That's this node.
How it works
It's translation, not scaling. The code takes your mask, copies it shifted along the direction you specify for every distance from 1 up to pixels, and unions all the copies with an elementwise max. The original mask stays put, so you get a "comet tail" growing out along one ray instead of a uniform inflate. pixels is how far the tip reaches; the rest of the shape is untouched.
Angle is measured clockwise in degrees, which trips people up the first time: 0 = up, 90 = right, 180 = down, 270 = left. Internally that's dir_x = sin, dir_y = -cos, so 0° really is straight up. Offsets get rounded to integers per step, so shallow angles like 15° stair-step a bit - normal, not a bug.
The inputs that matter
Only three, and two of them are the whole node:
mask- your input MASK.angle_deg- float, 0–360, default 0. Which direction to expand.pixels- int, 0–2048, default 0. How far to extend.
Output is a single MASK, ready to feed into anything that eats masks - SetLatentNoiseMask or InpaintModelConditioning for inpainting, ImageCompositeMasked for compositing, or a preview node while you dial it in.
Installing it
The pack is two nodes and nothing else. Via ComfyUI Manager, search "ComfyUI-MaskMorph" and install. Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/TheArtOfficial/ComfyUI-MaskMorph
Then restart ComfyUI (or reload custom nodes). There are no model downloads and requirements.txt is a comment saying torch comes from the ComfyUI runtime - nothing extra to pip install.
Gotchas worth knowing
The default is a no-op. pixels starts at 0, and the README is explicit: if pixels is 0, the mask comes back unchanged. Connect it, see nothing happen, and it's not broken - bump pixels. Same story with the classic confusion over angle direction: if your mask expands downward when you expected up, add 180.
Two more grounded in how the pack is built. First, this is a brand-new, single-commit repo with zero community footprint - no threads, no stars to speak of. It's a clean little utility, but it's not battle-tested, so preview the output before you wire it into a serious workflow. Second, the output has hard edges: there's no feathering here, just a clamp to 0–1. If you're expanding toward an inpaint region, run the result through a mask blur (4–12px is the usual range) or you'll get a seam you can see from across the room.
One thing the author got right: the node implements IS_CHANGED, so it won't recompute when its inputs are unchanged. Given how cheap these operations are that's marginal, but it does keep big graphs from re-running on every tick.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| angle_deg | FLOAT | 00–360 | — |
| pixels | INT | 00–2048 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |