Nodes/VLM_nodes/VLM Mask Composite
ComfyUI Node Runs on cloud

VLM Mask Composite

Cut your subject out, put it somewhere else, keep the plate

By gokayfem·Created 3 years ago·Updated 9 days ago· 583
VLM Mask Composite
  • image
  • mask
  • background
  • composite
  • foreground
  • background_only
  • mask_image
background_color#000000

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 background image 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.

CategoryVLM Nodes/Vision/Mask Tools

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
maskMASK
background_colorSTRING#000000#RRGGBB, #RGB, or R,G,B in the 0-255 range.
backgroundoptIMAGE

Outputs (4)

NameTypeDescription
compositeIMAGE
foregroundIMAGE
background_onlyIMAGE
mask_imageIMAGE