VLM Mask Processor
Every mask needs a cleanup pass. This is it.
- mask
- processed_mask
- binary_mask
- inverse_mask
- mask_image
No mask comes out of a model ready to use. Detection masks are rectangles with ragged confidence edges, SAM outputs have halo, and any mask from any source has that one stray pixel island you don't want. VLM Mask Processor is the cleanup pass: threshold it, grow or shrink it, feather it - and get a soft matte, a strict binary mask, an inverse, and a previewable image all from one node.
It's a mask tool in gokayfem's VLM_nodes pack, and the detail that makes it worth using over ComfyUI's scattered mask utilities is in the README: the grow/shrink and Gaussian feathering run in pure Torch, no OpenCV, no SciPy, no extra native deps to break your install. It accepts any Comfy MASK - including SAM2/SAM3 masks - so it slots into any pipeline.
How it works
Four inputs, all straightforward:
- mask (MASK) - any mask from anywhere.
- threshold - default 0.5. Soft masks get binarized at this cutoff for the strict output.
- grow_shrink - positive grows the mask, negative shrinks it (per the tooltip). Handy for pulling a mask in off the edges or expanding it to catch context.
- feather_radius - Gaussian feather in pixels. This is what turns a hard-edged cutout into a soft matte.
Outputs:
- processed_mask - the soft matte after threshold/grow/shrink/feather.
- binary_mask - a strict 0/1 version at your threshold.
- inverse_mask - the complement, for "everything except the subject" operations.
- mask_image - black-and-white preview so you can see the result without squinting at a tensor.
What to do with it
Typical chain: detection → masks → this node (shrink a few px to kill edge bleed, feather 2–4 px for a natural edge) → VLMMaskComposite or an inpaint node. Inverting here is also cheaper than adding another node - inverse_mask is free.
Installing this pack
Same one-pack install. ComfyUI Manager: search VLM_nodes. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/gokayfem/ComfyUI_VLM_nodes
cd ComfyUI_VLM_nodes
python -m pip install -r requirements.txt
Run pip with ComfyUI's Python. This node has no model downloads and no extra binary deps - that's the point.
Common issues
The tuning trap is threshold vs. feather: thresholding at 0.5 then feathering a few pixels is the sane order (and it's what the node does), but cranking feather up on a binary mask just rounds your corners - it doesn't restore lost detail. If the mask came from detection boxes, no amount of feathering fixes that the edges are box-straight; get polygon or SAM2.1 masks upstream for organic edges. And watch grow_shrink on small objects: shrinking by 10 px on a 30 px object erases it.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| threshold | FLOAT | 0.500–1 | — |
| grow_shrink | INT | 0-1024–1024 | Positive grows; negative shrinks the mask. |
| feather_radius | INT | 00–1024 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| processed_mask | MASK | — |
| binary_mask | MASK | — |
| inverse_mask | MASK | — |
| mask_image | IMAGE | — |