Nodes/MTB Nodes/Apply Vit Matte (mtb)
ComfyUI Node Runs on cloud

Apply Vit Matte (mtb)

Refine a rough mask into a real hair-level cutout

By melMass·Created 3 years ago·Updated about a month ago· 721
Apply Vit Matte (mtb)
  • model
  • image
  • trimap
  • image (rgba)
  • mask
returns

This is the node that turns a "good enough" cutout into an actually clean one. Apply Vit Matte runs the ViTMatte image-matting model over your image and a trimap, and predicts fractional alpha along the edges - the half-transparent pixels that make hair, fur, and soft edges look real instead of cut out with scissors.

The distinction that matters: most background-removal tools give you a segmentation mask, where every pixel is either subject or not. That's fine for a solid object and terrible for a head of hair, because a strand crossing a pixel makes that pixel genuinely part-subject, part-background. Matting predicts that in-between value. As the community puts it, a cutout that looks perfect against a grey preview and falls apart against a colored background is a segmentation model being asked to do a matting job. This node is the matting job.

How it works

ViTMatte is a transformer-based matting model. It doesn't find your subject - it refines one you already found. You give it the original image, plus a trimap marking definite-foreground, definite-background, and an unknown grey band, and it solves for the true alpha inside that unknown band. So the pipeline is always: segmenter → Generate TrimapApply Vit Matte. Skip the trimap and this node has nothing to work with.

The inputs and outputs that matter

  • model (VITMATTE_MODEL) - the loaded ViTMatte checkpoint, supplied by a loader node.
  • image (IMAGE) - the original full-color image.
  • trimap (IMAGE) - straight from Generate Trimap.
  • returns - RGB or RGBA. Pick RGBA if you want the transparency baked into the output image.

Two outputs: image (rgba) - the refined cutout - and mask - the predicted alpha as a MASK, which is often the more useful of the two since you can composite it however you like.

How to install it

Via ComfyUI Manager: search MTB Nodes, install, restart. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/melMass/comfy_mtb

then restart. ViTMatte needs its model weights downloaded - this is one of MTB's model-backed nodes. If the loader can't find the checkpoint, use MTB's own helper page at http://127.0.0.1:8188/mtb (it shows up in your console log on startup) or grab it through ComfyUI Manager's model manager.

Common issues & troubleshooting

Garbage in, garbage out. The matte is only as good as the trimap. If Apply Vit Matte gives you a mangled edge, the fix is almost always upstream - widen the unknown band in Generate Trimap so the model actually sees the hair, or clean up the segmentation mask feeding it.

It's not finding the subject. It's not supposed to. This node has no idea where your subject is; it trusts the trimap completely. You need a real segmentation step (BiRefNet, SAM, rembg) first - matting is the cleanup, not the detection.

Model won't load. Confirm the ViTMatte weights are actually downloaded and in the folder the loader expects. Missing weights is the usual cause of a red node here.

It's overkill for a solid object. If you're cutting out a phone or a car with clean edges, plain segmentation is fine and this whole trimap→matte dance is wasted effort. Save it for hair, fur, glass, and smoke.

Categorymtb/utils

Inputs (4)

NameTypeDefaultDescription
modelVITMATTE_MODEL
imageIMAGE
trimapIMAGE
returnsCOMBO2 options: RGB, RGBA

Outputs (2)

NameTypeDescription
image (rgba)IMAGE
maskMASK