Nodes/ComfyUI-CustomNodePacks/SeC + MatAnyone2 Pipeline
ComfyUI Node

SeC + MatAnyone2 Pipeline

SeC finds it, MatAnyone2 keeps it steady

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
SeC + MatAnyone2 Pipeline
  • image
  • bbox
  • rgb
  • alpha_mask
  • coarse_mask
  • preview
  • info
segmentation_modelsam2.1_hiera_base_plus
text_prompt
points_json[]
bbox_json
matting_backendauto
edge_radius15
n_warmup5
precisionfp16
fill_holes_enabledtrue
min_region_size64
positive_coords
negative_coords
edge_refine_methodnone
keep_model_loadedtrue

The hard version of matting is video. Per-frame, a static matting model gives you gorgeous hair edges that flicker from one frame to the next because nothing remembers the previous frame. The production fix is a temporal matting model that carries a memory, and that's what this pipeline assembles: SeC - a segmentation model with a vision-language backbone that understands "the cat" or "person in red" as a semantic target - produces the coarse masks, and MatAnyone2's temporal alpha matting refines them into a stable, compositing-grade alpha across the whole clip. It's the pack's answer to "mask this thing for the entire shot," and it's the one with text prompts and occlusion handling built in.

The flow

The flow: you feed image (single frame, or a batch B>1 for video) and describe the target in text_prompt ("cat", "person in red"). SeC uses that language understanding to track the object semantically - which is the whole advantage over point-clicking when the subject occludes and reappears, or changes shape. Leave text_prompt empty and it drops to point/bbox prompting (points_json / bbox_json, plus optional positive_coords/negative_coords from a Points Mask Editor and a bbox from upstream). Then matting_backend does the edges: auto picks MatAnyone2 for video and ViTMatte for single images; matanyone2 is the temporal engine, with n_warmup (default 5) frames of warmup - more warmup, better temporal initialization.

Why it beats plain SAM+ViTMatte on video

The mechanism detail that matters: SeC tracks semantically, MatAnyone2 refines temporally, and the alpha carries that memory through occlusions and re-appearances - the exact failure mode the README calls out for plain SAM+ViTMatte, which has no temporal component. After matting you get optional edge_refine_method (vitmatte / guided_filter / multi_scale_guided) for a last edge pass, then cleanup: fill_holes_enabled and min_region_size (64).

Outputs

Outputs: rgb (the original frames, passed through for downstream), alpha_mask (the compositing-grade alpha), coarse_mask (the pre-matting segmentation - keep it for before/afters), preview (input + alpha overlay), and info (JSON of stages, models, per-stage timings). precision (default fp16) applies to the segmentation model, and keep_model_loaded (default on) holds the models in VRAM between runs - turn it off if you're juggling a big diffusion model on the same card.

Install

Install is the pack's most involved setup: clone Code2Collapse/ComfyUI-CustomNodePacks into custom_nodes (or Manager → "CustomNodePacks"), then the model downloads. SeC weights plus MatAnyone2 (and ViTMatte, if you want that backend) - the README's licensing table is worth a skim: everything here is Apache-2.0 or MIT, so it's commercial-safe, unlike the pack's RMBG-2.0 background-remover option. Expect a multi-GB first-run download and real VRAM during video inference; this is a "make sure your card can breathe" pipeline, not a quick preview node. But for a clean, temporally-stable cutout of one named thing across a shot, it's the right tool.

CategoryC2C/Pipeline

Inputs (16)

NameTypeDefaultDescription
imageIMAGESingle image or video frames (B>1 for video).
segmentation_modelCOMBOsam2.1_hiera_base_plusSegmentation model for coarse masks. SeC: best for video with text prompts. SAM2/3: best for point/bbox prompts.
text_promptSTRINGText description of target object (e.g. 'cat', 'person in red'). Used by SeC for semantic tracking. Leave empty for point/bbox prompts.
points_jsonSTRING[]Point prompts: [{"x":100,"y":200,"label":1}, ...]
bbox_jsonSTRINGBounding box: [x1,y1,x2,y2]
matting_backendCOMBOautoAlpha matting backend. auto: MatAnyone2 for video (B>1), ViTMatte for single images. matanyone2: Video matting with temporal consistency. vitmatte_small/base: Neural matting (best edge quality per frame).
edge_radiusINT151–200Edge refinement radius in pixels.
n_warmupINT51–30MatAnyone2 warmup frames (more = better temporal init).
precisionCOMBOfp16Segmentation model precision.
fill_holes_enabledBOOLEANtrueFill interior holes in the final alpha.
min_region_sizeINT640–10000Remove isolated regions smaller than N pixels.
positive_coordsoptSTRINGPositive points from Points Mask Editor.
negative_coordsoptSTRINGNegative points from Points Mask Editor.
bboxoptBBOXPositive bbox from upstream node.
edge_refine_methodoptCOMBOnoneOptional post-matting edge refinement. none: use raw MatAnyone2 output. vitmatte/guided_filter: refine edges after matting.
keep_model_loadedoptBOOLEANtrueKeep models in VRAM between runs.

Outputs (5)

NameTypeDescription
rgbIMAGEOriginal RGB frames passed through for downstream nodes.
alpha_maskMASKCompositing-grade alpha mask after MatAnyone2 + optional refinement.
coarse_maskMASKCoarse segmentation mask before alpha matting.
previewIMAGESide-by-side preview of input frames and final alpha overlay.
infoSTRINGJSON summary of stages, models, and per-stage timings.