Erode Mask Regions
Shrink a mask in from its edges
- masks
- MASKS
Auto-generated masks - from CLIPSeg, from a segmentation model, from anything that isn't a human carefully drawing a boundary by hand - tend to bleed a few pixels past the actual edge of whatever they're supposed to be masking. SaltMaskErodeRegion fixes that by shrinking the mask inward, a classic morphological operation borrowed straight from computer vision (this is the same erosion cv2.erode does, applied to your MASK data).
What it does
One required input beyond the mask itself: iterations (integer, default 5, range 1–64). Each iteration eats another ring of pixels off the mask's boundary, pulling every edge inward by roughly a pixel per pass. More iterations, more shrinkage. The output, MASKS, is the eroded mask.
Why you'd want a smaller mask
The most common reason is avoiding a halo or fringe artifact around a subject in an inpaint. If your mask bleeds a little past the actual object - a stray pixel or two of background caught inside a "mask the subject" selection - inpainting with that mask can leave a faint ring of the wrong content at the boundary once the paste-back happens. Eroding the mask a few pixels in from the true edge before you use it trims that margin of error away. It's also useful for cleaning up a sloppy hand-drawn or auto-generated mask that's just generally a bit too generous around its target.
Installing it
ComfyUI Manager: search SaltAI-Open-Resources. Manual install:
cd ComfyUI/custom_nodes
git clone https://github.com/get-salt-AI/SaltAI
Restart ComfyUI. No models or extra dependencies - this is pure morphological image processing.
Common issues
Push iterations too high relative to the size of what you're masking and the mask can vanish entirely - erosion eats from every edge simultaneously, so a thin or small region has much less margin than a large one before it's eroded down to nothing. Start low (the default of 5 is a reasonable first try) and increase only as much as you actually need. If your mask is soft/grayscale rather than a clean binary shape, erosion on partial values can behave less predictably than you'd expect - for the cleanest morphological result, run this pack's SaltMaskThresholdRegion first to binarize the mask, then erode, rather than eroding a fuzzy mask directly. And if you need the opposite operation - growing a mask outward instead of shrinking it - this node only shrinks; look elsewhere in the pack's masking filters or combine an inverted erode with SaltMaskAdd if you need dilation-style behavior.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | — | |
| iterations | INT | 51–64 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASKS | MASK | — |