MaskErode(腐蚀)
Shrink a mask's edges inward
- mask
- MASK
The mirror image of this pack's MaskDilate, and its display name says so directly: MaskErode(腐蚀) - 腐蚀 literally means "corrode." Where dilate pushes a mask's edge outward, erode pulls it inward, shrinking the masked region.
Why you'd shrink a mask
The usual reason is the opposite of dilate's: your mask overshoots. Auto-segmentation is often a little generous around the edges - a SAM or CLIPSeg mask that includes a rim of background along with the subject. Pull the boundary in before you composite or inpaint with it, and you keep the generation from touching pixels just outside where you actually wanted it. It's also a deliberate move on its own: shrinking a mask to just the core of a region and letting a generative fill extend naturally outward from there can read more seamlessly than painting right up to an oversized boundary.
Inputs and outputs
mask(MASK) - what you're shrinking.kernel_height,kernel_width(FLOAT, 0–1, default0.005) - how far the mask contracts, one value per axis.- Output:
MASK.
The same gotcha as its sibling
kernel_height/kernel_width are a fraction of the mask's dimension (0 to 1), not a pixel count - the exact same convention as MaskDilate, and the exact same trap if you're carrying habits from a pixel-based grow/shrink node in another pack. Default 0.005 is roughly 5px on a 1024px mask. Push the value up expecting a modest pixel-scale shrink and you can eat the entire mask well before you get near 1.0 - erode is more punishing than dilate in this respect, because there's a hard floor: once the shrink exceeds what's left of the masked region, the mask is just gone.
That's the one failure mode specific to erode and worth calling out on its own: an over-aggressive erode doesn't error, it just quietly returns an empty mask. Downstream, that reads as "nothing happened" - no crash, no warning, just a generation that regenerated nothing because there was nothing left to select. If a mask-dependent step in your graph is doing nothing at all, check here before you go hunting elsewhere.
Installing it
ComfyUI Manager: search RuiquNodes, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/ruiqutech/ComfyUI-RuiquNodes
then restart. No model downloads needed.
Common issues
Mask disappears entirely. Covered above - you've eroded past what the mask had left. Back the kernel values off, in small increments (0.001–0.002 at a time), until something survives.
Barely any visible shrink. You're still in a small fraction of the dimension. This node's useful range is much narrower than a pixel-count node - nudge gradually rather than jumping.
Combining with dilate. Erode-then-dilate (or the reverse) is a standard morphology trick for cleaning up a mask's shape - erode to strip thin stray bits, dilate back to restore size without the noise. Both nodes live in the same ruiqu/mask category if you want to chain them.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| kernel_height | FLOAT | 0.00500–1 | — |
| kernel_width | FLOAT | 0.00500–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |