Nodes/ComfyUI Impact Pack/Dilate Mask (SEG_ELT)
ComfyUI Node Runs on cloud

Dilate Mask (SEG_ELT)

Grow or shrink one detection's mask inside the decompose/assemble loop

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,242
Dilate Mask (SEG_ELT)
  • seg_elt
  • SEG_ELT
dilation10

Impact Pack has three versions of the same idea - grow or shrink a mask's edges by a set number of pixels - depending on what shape your mask currently lives in. Dilate Mask works on a plain MASK. Dilate Mask (SEGS) works on every mask inside a whole SEGS batch at once. This one, Dilate Mask (SEG_ELT), works on a single decomposed detection element - the SEG_ELT you get from pulling a SEGS apart with DecomposeSEGS. It's for when you need to adjust one detection's mask differently from the rest, rather than applying the same dilation to every region in a batch.

How it works

Once you've decomposed a SEGS into its header plus a list of individual SEG_ELTs, each element carries its own cropped image, mask, bounding box, and metadata. This node applies a standard morphological dilation to just that one element's mask - positive values grow it outward, negative values shrink it inward, same signed-value convention as its MASK- and SEGS-scoped siblings. Everything else about the element - its bounding box, crop region, confidence, label - passes through untouched; only the mask changes. The result feeds back into the same decompose/edit/assemble loop as Edit SEG_ELT: pull apart, adjust individually, put back together with AssembleSEGS.

The inputs and output

  • seg_elt (SEG_ELT, required) - the single detection element to adjust. Get this from DecomposeSEGS.
  • dilation (INT, default 10, range −512 to 512, step 1) - signed pixel amount. Positive dilates (grows the mask, more room for a detail pass to blend into); negative erodes (shrinks it, tighter fix, less spillover into surrounding pixels). Realistic values are usually small - single or low double digits.

Output is a single SEG_ELT with the same detection data and a resized mask, ready to feed back into AssembleSEGS (with the original SEGS_HEADER) to become a normal SEGS again.

How to install it

Ships with the Impact Pack. ComfyUI Manager: search ComfyUI Impact Pack, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
pip install -r requirements.txt

then restart. No models - pure mask math, same as its MASK- and SEGS-level siblings.

Common issues & troubleshooting

Do you actually need the SEG_ELT version? Only if you're already decomposing the SEGS for other per-element work (relabeling with Edit SEG_ELT, reading exact coordinates with From SEG_ELT) and want the dilation to happen in that same loop. If you just want to grow every mask in a SEGS by the same amount, Dilate Mask (SEGS) does that in one step without you decomposing and reassembling anything.

Forgot to reassemble. Adjusting the element alone changes nothing downstream - feed the result, along with the SEGS_HEADER from DecomposeSEGS, into AssembleSEGS before it reaches a detailer or paste node.

Mask vanished after a large negative dilation. Same failure mode as the other Dilate Mask variants: erode past a mask's own size and it disappears entirely. Reduce the magnitude if the mask was small to begin with.

Hard edge after dilating. Dilation resizes the mask but doesn't soften it - the boundary stays crisp. Follow with Gaussian Blur Mask on the assembled result, or feather at the paste step, if you want a blended transition too.

CategoryImpactPack/Util

Inputs (2)

NameTypeDefaultDescription
seg_eltSEG_ELT
dilationINT10-512–512

Outputs (1)

NameTypeDescription
SEG_ELTSEG_ELT