Dilate Erode Mask (Badman)
Grow or shrink a mask with one signed slider
- masks
- MASK
Mask morphology usually comes as two separate operations you have to remember to chain - a dilate node to grow a mask, an erode node to shrink one. Badman collapses both into a single node with a signed radius: positive numbers grow the mask, negative numbers shrink it. One node, one slider, both directions.
Why you'd want to grow or shrink a mask at all
If you've done any inpainting or compositing, you've hit this problem: the mask you get out of a segmentation model, a manual paint, or a matte-cleanup step is rarely exactly the boundary you want to act on. Grow it (dilate) a few pixels and you buy yourself margin - useful when you want an inpaint to blend a little past the exact subject edge so there's no hard seam, or when you're feeding a mask into a ControlNet-style guide and want a bit of slack around the region. Shrink it (erode) and you pull the boundary in from the edges - handy for trimming off a soft, noisy fringe a segmentation model left behind, or for making sure a mask doesn't touch pixels that belong to the background. This node does both jobs from the same input, which means you can wire it once and just flip the sign of radius depending on which direction you need that pass.
Inputs and outputs
Three required fields:
masks- theMASKyou're operating on.radius(integer,-1023to1023, default0, step1) - the size and direction of the operation. Positive dilates (grows), negative erodes (shrinks),0is a no-op pass-through. The huge range means you can do anything from a one-pixel nudge to a dramatic reshape, though anything past a couple hundred pixels on a large mask is going to visibly balloon or eat the shape rather than just cleaning an edge.shape- an enum,boxorcircle, the structuring element used for the operation.boxgrows/shrinks along axis-aligned edges and will noticeably square off corners on anything past a small radius;circlekeeps corners rounded and generally looks more natural on organic subjects. If your dilated mask is coming out with weirdly sharp, blocky corners, that'sboxdoing exactly what it's supposed to - switch tocircle.
One output: the modified MASK, same shape and semantics as the input, ready to feed into inpainting, compositing, or another mask-processing step.
Installing it
ComfyUI Manager: search ComfyUI-BadmanNodes, install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/MariusKM/ComfyUI-BadmanNodes
Restart ComfyUI. No dependencies or model downloads noted in the README for this node - it's pure mask-tensor math, so install is as clean as it gets.
Where people get tripped up
The main trap is forgetting the range is signed and reaching for a separate erode node out of habit when you actually just needed a negative radius here. The second is scale mismatch: a radius value that looks reasonable on a 512px test image can be wildly too aggressive (or too subtle to notice) once you're working at 2K or 4K, since this is a pixel-radius value, not a percentage of the mask's size - recheck it whenever your resolution changes. And if you're chaining this before something like a Gaussian mask blur, do the dilate/erode pass first and blur after; blurring a hard-edged mask and then reshaping it tends to reintroduce the harsh edge you just spent a blur pass softening.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | — | |
| radius | INT | 0-1023–1023 | — |
| shape | COMBO | 2 options: box, circle |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |