VLM Mask Composite
Cut your subject out, put it somewhere else, keep the plate
- image
- mask
- background
- composite
- foreground
- background_only
- mask_image
The classic VLM trick: detect the person, build a mask, and you want to see the person standing on a green screen, or over a new background, or floating alone on black. Doing that in ComfyUI usually means stringing together half a dozen nodes. VLM Mask Composite collapses it into one - apply a mask to an image or a video batch and get the composited result, the isolated foreground, the original background-only plate, and a mask preview, all at once.
It's a mask tool in gokayfem's VLM_nodes pack, and it plays nicely with the rest of the detection family: VLMDetectionsToMasks builds the mask from detections, VLMMaskProcessor cleans it up, and this node does the actual cut-and-place.
How it works
You give it an image (still or a whole video frame batch), a mask, and a background_color like #000000, #000, or 0,0,0 (the tooltip spells out the accepted formats). It composites the masked region over that solid color. Optionally you can supply a background IMAGE instead - a real photo or a generated plate - and the subject gets placed over that. A single mask or background safely broadcasts across a whole video batch, so one subject mask can composite over every frame of a clip.
The four outputs are the useful part:
- composite - foreground over your color or background.
- foreground - the subject cut out, isolated.
- background_only - the original background plate with the subject removed.
- mask_image - black-and-white mask preview for a quick sanity check.
That "background_only" output is worth its weight: it's a clean, unmasked plate you can inpaint, replace, or reuse without another pass.
Inputs and outputs that matter
- image (IMAGE) - source, still or video batch.
- mask (MASK) - whatever mask you have; it doesn't care where it came from.
- background_color - fallback when no
backgroundimage is supplied. - background (optional IMAGE) - the plate to composite over.
Outputs: composite, foreground, background_only, mask_image.
Installing this pack
One pack, one 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
ComfyUI's Python for pip; no model downloads for this node.
Common issues
Mask quality is everything here - a box-shaped mask from detection rectangles gives you a box-shaped cutout. Run your mask through VLMMaskProcessor (feather, grow/shrink) or get proper segmentation masks (SAM2.1) first, and the composite stops looking like a cardboard cutout. Color format trips people too: background_color wants hex or R,G,B in 0–255, not a named color or a 0–1 tuple. And if frames are large, remember this node returns full-resolution copies of everything - four outputs of a 4K clip is a lot of memory.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| background_color | STRING | #000000 | #RRGGBB, #RGB, or R,G,B in the 0-255 range. |
| backgroundopt | IMAGE | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| composite | IMAGE | — |
| foreground | IMAGE | — |
| background_only | IMAGE | — |
| mask_image | IMAGE | — |