ComfyUI Node
TS Matting (ViTMatte)
Guided matting via Hugging Face ViTMatte. Builds an auto-trimap from a coarse binary MASK (erode for confident foreground, dilate for the unknown band), then refines the alpha with hair / fur / semi-transparency. Drop-in for TS Remove Background when you already have a SAM3 mask.
TS Matting (ViTMatte)
- image
- mask
- background_color
- IMAGE
- MASK
- MASK_IMAGE
◄modelvitmatte-base-composition-1k►
◄trimap_erode_px10►
◄trimap_dilate_px20►
◄max_resolution2048►
◄auto_crop_by_masktrue►
◄crop_padding_pct15►
◄precisionauto►
◄temporal_smoothmedian3►
◄ema_alpha0.50►
◄mask_blur0►
◄mask_offset0►
◄invert_outputfalse►
◄backgroundAlpha►
CategoryTS/Image/Cutout
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Source image batch [B, H, W, 3]. | |
| mask | MASK | Coarse binary or soft MASK [B, H, W] (e.g. from SAM3 Detect or SAM3 Video Track). A single-frame mask is broadcast across the image batch. | |
| model | COMBO | vitmatte-base-composition-1k | ViTMatte variant. 'base' = ~370 MB (recommended for best edge quality), 'small' = ~96 MB (faster, lower detail). 'composition-1k' is the standard matting benchmark; 'distinctions-646' is more diverse. |
| trimap_erode_px | INT | 100–128 | Erosion radius for the confident foreground core. Higher = thinner certain-foreground, more soft edges (better for hair). |
| trimap_dilate_px | INT | 200–128 | Dilation radius for the unknown band beyond the mask. Higher = ViTMatte gets more context around the object (helps fly-away hair / fur). 20 is a good default; bump to 32+ if the source mask is tight around hair/fur. |
| max_resolutionopt | INT | 20480–4096 | Long-edge cap (px) for ViTMatte inference. ViTMatte uses global self-attention in some ViT blocks; on 4K input that single attention matrix needs ~25 GB of VRAM. The frame is downscaled before inference and the resulting alpha is upscaled back to native size. 0 = use the native resolution (only safe for small images / lots of VRAM). |
| auto_crop_by_maskopt | BOOLEAN | true | Crop the frame to the mask's bounding box (plus padding) before running ViTMatte. Saves enormous amounts of VRAM and time when the object is small compared to the frame. Has no effect when the mask covers the whole frame. |
| crop_padding_pctopt | INT | 150–100 | Padding around the mask bbox in percent of bbox size when ``auto_crop_by_mask`` is on. 15 = 15% context margin. |
| precisionopt | COMBO | auto | Inference precision on CUDA. 'auto' picks bf16 on Ampere+ (more numerically robust, no fp16 inf/nan on extreme alpha) and fp16 elsewhere. Force 'fp32' for diagnostics. CPU always runs fp32. |
| temporal_smoothopt | COMBO | median3 | Smooth alpha across frames to reduce 'boiling' edges in video. 'median3' (default) kills random 1-frame flicker with minimal overhead and is a no-op for single images. 'median5' for stronger flicker (2-frame lag at clip boundaries). 'ema_causal' is causal exponential averaging — no lag, but can blur fast motion. 'off' disables. Peak RAM grows by ~N*H*W*4 bytes during the pass. |
| ema_alphaopt | FLOAT | 0.500–0.99 | Strength of the causal EMA when temporal_smooth = 'ema_causal'. Higher = more smoothing (lag for moving objects); lower = closer to raw per-frame alpha. |
| mask_bluropt | INT | 00–64 | Final Gaussian blur on the alpha output (px). |
| mask_offsetopt | INT | 0-20–20 | Shrink (-) / expand (+) the final alpha mask. |
| invert_outputopt | BOOLEAN | false | Invert the alpha output. |
| backgroundopt | COMBO | Alpha | Output background mode. |
| background_coloropt | COLOR | #ffffff | Solid background colour when 'background' = 'Color'. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | Cutout image (RGBA or composited on the chosen background). |
| MASK | MASK | Refined alpha matte. |
| MASK_IMAGE | IMAGE | Alpha matte as a grayscale image for preview. |