Code2Collapse/ComfyUI-CustomNodePacks

Experimental nodes! This is a production suite for ComfyUI — SAM2.1/SAM3 segmentation, alpha matting, inpaint crop/stitch, VFX tools (EXR I/O, LUTs, render passes), video mask propagation, temporal anchors, VAE merging, spline editors, and auto-versioned output.

54

stars

555

commits

Python

primary language

Sep 10, 2026

updated

README

MEC Logo

📖 Full node & parameter reference

NODE_REFERENCE.md documents every node in this pack: each input's type, default, valid range and what it actually does, plus every output. It is generated directly from the live NODE_CLASS_MAPPINGS, so the descriptions there are the same strings you see as tooltips in ComfyUI and cannot drift out of date. Start there when you want to know what a knob does; read on here for how the pieces fit together.

ComfyUI-CustomNodePacks

MaskEditControl (MEC) + FolderIncrementer + VFX Suite
Production-grade mask editing, SAM1/2/3 segmentation, alpha matting, inpainting, diagnostics,
temporal mask interpolation, luminance keying, color science, EXR I/O, render-pass
compositing, plate tools, VAE merging & analysis, and auto-versioned file output for ComfyUI.

InstallationNode ReferenceWorkflowsTroubleshootingAcknowledgementsLicense


⚠️ Non-Commercial Model Notice: The RMBG-2.0 model weights (briaai/RMBG-2.0) are subject to the BRIA AI RMBG License, which restricts commercial use. If you use the Background Remover node with the rmbg_2.0 backend for commercial purposes you must obtain a commercial licence from Bria AI at https://bria.ai. All other models used in this pack (SAM, SAM2, BiRefNet, ViTMatte, SeC, etc.) are Apache-2.0 or MIT licensed and may be used commercially. See NOTICE.md for full attribution and license details.


Overview

ComfyUI-CustomNodePacks ships 72 nodes organized into the following packs:

PackNodesPurpose
MaskEditControl (MEC)33Pinpoint mask editing, SAM1/2/3 segmentation, SAM multi-mask picker, SeC + MatAnyone2 pipeline, background removal, face/clothes parsing, ViTMatte alpha matting, luminance keying, inpaint crop/stitch/paste-back suite, image comparison, mask failure diagnostics, temporal anchor interpolation, video propagation, compositing tools
VAE Tools4Merge two/three VAEs (8 algorithms, per-block alpha), latent inspector, similarity analyser, per-block weight inspector
VFX Suite19Color-space convert (sRGB/linear/Rec.709/ACEScg), .cube LUT apply, exposure/grade, EXR load+save, merge render passes, depth-of-field mask, depth warp, normal→curvature, position-pass splitter, grain match, plate stabilizer, clean-plate extractor, difference matte, metadata writer, frame-range router, shot-metadata reader
Diagnostics5EXR metadata reader, batch version manager, temporal consistency checker, model metadata extractor, parameter history
FolderIncrementer3Filesystem-safe auto-versioned output (v001, v002, …) with name sanitization and atomic version reservation
Universal Reroute1Nuke-style Dot node — reroute any wire type for cleaner workflow graphs
Parameter Memory1Tracks every parameter change with SQLite history, defaults recall, and per-run diffing

All nodes are prefixed with (MEC) in the ComfyUI node menu for easy discovery.

Who is this for?

  • VFX / compositing artists who need Nuke-quality mask control inside ComfyUI
  • Video creators who need temporally consistent masks across hundreds of frames
  • Inpainters who want crop → inpaint → stitch pipelines with edge-aware blending
  • Anyone tired of SAM giving 3 masks and not knowing which one to pick
  • Beginners who want one-click background removal or a node that tells them why their mask failed

Installation

1. Clone the repo

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

Or install via ComfyUI Manager → search "CustomNodePacks".

2. Install dependencies

⚠️ IMPORTANT: Check your existing package versions before installing.

ComfyUI bundles its own torch, torchvision, numpy, and Pillow. Blindly running pip install -r requirements.txt can overwrite them with incompatible versions and break your ComfyUI installation.

Recommended approach: Open requirements.txt, comment out anything already installed, and only install what you're missing:

# Check what you already have:
pip list | grep -i "opencv\|scipy\|safetensors\|transformers"

# Then install only what's missing:
pip install opencv-python>=4.7.0 scipy>=1.10.0 safetensors>=0.4.0

The requirements.txt lists:

PackageRequired?Purpose
opencv-pythonYesEdge detection, morphological ops, guided filter
scipyYesGaussian filters, signal processing
safetensorsYesSafe model weight loading
transformersOptionalViTMatte neural matting (best quality edges)
pillowOptionalImage I/O for ViTMatte

Core packages (torch, torchvision, numpy) are already provided by ComfyUI — do not reinstall them.

3. Place SAM model checkpoints

Download SAM 2.1 / SAM 3 weights and place them in:

ComfyUI/models/sams/        ← SAM 3
ComfyUI/models/sam2/        ← SAM 2.1
ModelFileSource
SAM2.1 Largesam2.1_hiera_large.ptMeta AI
SAM3sam3_hiera_large.ptMeta AI

The SAM Model Loader node auto-detects model type from the filename.

Note: Legacy SAM 1 (ViT-H/L/B) and the original SAM 2.0 line are no longer supported. Only SAM 2.1 and SAM 3 are exposed.

4. (Optional) ViTMatte matting

For the highest-quality edge refinement (hair, fur, glass, lace):

pip install transformers pillow

The ViTMatte model (~400 MB) auto-downloads from HuggingFace on first use. For offline setups, place model files in ComfyUI/models/vitmatte/.

5. Restart ComfyUI

Look for [MEC] Loaded 44 MaskEditControl nodes. in the console to confirm.


Detailed Documentation

📚 Start here: docs/README.md — the central documentation index with quick-nav by task, pack-by-pack reference, and image-vs-video pipeline guidance.

Every node's parameters, modes, and outputs are documented in depth in the docs/ folder:

GuideNodesWhat's inside
Documentation IndexCentral nav: quick lookup by task, pack-by-pack reference, image-vs-video helpers
Inpaint Suite4Crop Pro, Stitch Pro, Paste Back, Mask Prepare — full pipeline with fill modes, blend modes, interpolation methods
ProPainter Suite ★ new5Temporal video inpaint, stitch (drop-in for legacy), seam-only refine, model-free remove, RAFT flow refine
Face Fixer ★ new1YOLO11 face detection → per-face KSampler → smart blend with [SEP]/[ASC]/[DSC]/[SKIP] wildcard prompts
Paint Suite ★ new2Interactive paint canvas (hardness/expansion/blur stages) + smart context inpainter (color match, lightness rescue, differential diffusion)
Mask + Matting Pipeline ★ new1Combined MaskMattingMEC — pick segmenter (SAM2.1/SAM3/SeC/…) + matter (ViTMatte/RVM/MatAnyone2/…) + slot-based prompts
Video Stabilizer ★ new3Classic GFTT+LK / RAFT dense flow / auto-router with 4 presets; padding-mask output wires into Inpaint Crop Pro
Mask Editing8Transform XY, Draw Frame (12 shapes), Draw Shape (unified dropdown), Composite Advanced (8 ops), Math (11 ops), Batch Manager, Preview Overlay, Spline Mask Editor
SAM & Segmentation8Model Loader, Mask Generator, Multi-Mask Picker, Unified Segmentation, Semantic Segment, Background Remover, both pipelines
Matting & Refinement4Matting Node (7 backends), ViTMatte Refiner (7 methods), Trimap Generator, Luminance Keyer
Video, Temporal & BBox10Frame Extractor, Mask Propagate (5 modes), Temporal Anchor (SDF), Motion Mask Tracker (4 methods), 6 BBox nodes
Utility & Interactive8Points Mask Editor, Image Comparer, Mask Failure Explainer, Parameter History, Universal Reroute, 3 Folder Incrementer nodes
VAE Tools4VAE Merge (8 algorithms), Latent Inspector, Similarity Analyser, Block Inspector
Color Science3sRGB/linear/Rec.709/ACEScg convert, .cube LUT apply, exposure/WB/contrast grade
EXR I/O2Load and save OpenEXR with imageio + TIFF fallback chain
Render Passes2Merge beauty + AO/diffuse/spec/emission, depth→CoC mask
Plate Tools4Grain match, plate stabilizer (ORB/FFT), clean-plate extractor, difference matte
Video Frame Player1In-graph scrubber + drag-crop (8 handles, aspect-lock) + trim range + frame-stride + lanczos resize/upscale, all in one node

Node Reference

Legend

All nodes appear in the ComfyUI menu under MaskEditControl/ categories.

SymbolMeaning
★★★★★Best quality (may need optional deps)
★★★★☆Great quality
★★★☆☆Good / fast fallback

Segmentation & SAM

SAM Model Loader (MEC)

Loads SAM 2.1 / SAM 3 checkpoints with optional VRAM offload.

ParameterDefaultDescription
model_nameCheckpoint filename (auto-listed from models/sams/ and models/sam2/)
model_typeautoForce type: sam2.1, sam3, or auto
devicecudacuda / cpu
offload_to_cpufalseKeep model on CPU, move to GPU only during inference (saves ~2–4 GB VRAM)
dtypefloat16float16 / bfloat16 / float32

Output: SAM_MODEL — connect to SAM Mask Generator, SAM Multi-Mask Picker, or SAM + ViTMatte Pipeline.


SAM Mask Generator (MEC)

Runs SAM 2.1 / SAM 3 inference with point + bbox prompts, iterative refinement, and auto-negative point sampling.

ParameterDefaultDescription
imageInput image
sam_modelFrom SAM Model Loader
points_json""[{"x":int, "y":int, "label":1}, ...]
bbox_json""[x1, y1, x2, y2]
multimasktrueReturn 3 candidate masks
mask_index0Which candidate (0–2) to use
refine_iterations1Iterative SAM passes (each tightens boundaries)
auto_negative_points0Sample N negative points from outside the mask

Outputs: masks, best_score, info


SAM Multi-Mask Picker (MEC)

Run SAM inference and view all 3 candidate masks side-by-side with IoU scores. An interactive JS widget renders thumbnails — click a mask or press 1 / 2 / 3 to select it instantly.

How it works: SAM always outputs 3 masks ranked by confidence. Instead of guessing which mask_index is best, this node shows all three with quality scores and lets you pick visually. Works with SAM1, SAM2, and HQ-SAM.

ParameterDefaultDescription
imageInput image
model_nameSAM model (SAM1 / SAM2 / HQ-SAM, auto-listed)
points_json[{"x":256,"y":256,"label":1}]Point prompts JSON
bbox_json""Optional bounding box [x1,y1,x2,y2]
precisionfp32fp32 / fp16 / bf16
selected_index0Which candidate (0–2) — updated by widget click
sam_model(optional)Pre-loaded SAM model from SAM Model Loader
bbox(optional)BBox from BBox pipeline (overrides bbox_json)

Outputs: selected_mask, all_masks (3×H×W), selected_index, scores (JSON), info

Who is it for? When SAM gives you 3 options and you don't know which is best — see them all at once, pick with one click, and pipe the winner downstream.


Unified Segmentation (MEC)

One-node dispatcher for SAM 2.1, SAM 3, SeC, VideoMaMa with automatic image vs. video detection.

ParameterDefaultDescription
model_nameModel selector
points_json / bbox_json""Point and box prompts
precisionfp16fp16 / bf16 / fp32
attention_modeautosdpa / flash_attn / sage_attn / xformers
text_prompt(optional) Text prompt for grounding models

Outputs: masks, best_score, info


SAM + ViTMatte Pipeline (MEC)

End-to-end pipeline: SAM coarse segmentation → iterative refinement → neural alpha matting in a single node. Best possible masking quality for single images.

ParameterDefaultDescription
sam_iterations2Iterative SAM passes
refine_methodautoauto / vitmatte / multi_scale_guided / color_aware / laplacian_blend
edge_radius12Pixels around edges to refine
detail_preservation0.85Fine detail retention (hair, fur, lace)
edge_contrast1.0Edge sharpness boost (>1 = sharper)
fill_holestrueFill holes inside mask
remove_small_regions64Remove noise < N pixels

Outputs: refined_mask, coarse_mask, edge_mask, preview, detected_bbox, score, info

Pipeline stages:

  1. SAM coarse mask from point/bbox prompts
  2. Iterative refinement (re-run SAM with mask-derived prompts)
  3. Edge-aware matting (ViTMatte / guided filter / LAB color)
  4. Edge contrast boost
  5. Post-processing (hole fill, small region removal)

SeC + MatAnyone2 Pipeline (MEC)

End-to-end pipeline: SeC MLLM segmentation → MatAnyone2 temporal alpha matting in a single node. Best for video masking with temporal consistency.

ParameterDefaultDescription
segmentation_modelSeC / SAM2 / SAM3 model selector
text_prompt""Text description of target object (e.g. "cat", "person in red")
matting_backendautoauto / matanyone2 / vitmatte_small / vitmatte_base
edge_radius15Edge refinement radius in pixels
n_warmup5MatAnyone2 warmup frames (more = better temporal init)
edge_refine_methodnoneOptional post-matting refinement: vitmatte / guided_filter / multi_scale_guided
fill_holes_enabledtrueFill interior holes in alpha
min_region_size64Remove isolated regions < N pixels

Outputs: rgb (premultiplied), alpha_mask, coarse_mask, preview, info

Pipeline stages:

  1. SeC/SAM coarse segmentation (text or point/bbox prompts)
  2. MatAnyone2 temporal alpha matting with warmup protocol
  3. Optional edge refinement (ViTMatte / guided filter)
  4. Post-processing (hole fill, small region removal)

Key advantages over SAM + ViTMatte:

  • SeC uses a Vision-Language Model for semantic understanding (text prompts)
  • MatAnyone2 provides temporal consistency across video frames
  • Better for long sequences with occlusions and re-appearances

Semantic Segment (MEC)

Face / body / clothes semantic parsing using SegFormer. Select classes by name to build a combined mask.

ParameterDefaultDescription
model_namesegformer_face (19-class facial) or segformer_clothes (18-class apparel)
classes_csv"skin,hair"Comma-separated class names to include
threshold0.5Confidence threshold
invertfalseInvert output mask

Face classes: skin, l_brow, r_brow, l_eye, r_eye, eye_g, l_ear, r_ear, ear_r, nose, mouth, u_lip, l_lip, neck, necklace, cloth, hair, hat

Clothes classes: hat, hair, sunglasses, upper_clothes, skirt, pants, dress, belt, left_shoe, right_shoe, face, left_leg, right_leg, left_arm, right_arm, bag, scarf

Output: mask, info

Who is it for? Portrait retouchers who need to isolate specific facial features or clothing items without manual masking.


Alpha Matting

Background Remover (MEC)

One-click background removal using RMBG-2.0 or BiRefNet. Outputs a clean foreground and alpha mask.

ModelQualityBest for
rmbg_2.0★★★★☆General-purpose, fast
birefnet_general★★★★★High-detail edges
birefnet_portrait★★★★★Human portraits
ParameterDefaultDescription
model_nameBackground removal model selector
threshold0.5Alpha threshold (0 = soft, 1 = hard)
invertfalseKeep background instead
mask_blur0Gaussian blur on mask edges

Outputs: foreground (premultiplied RGB), mask, info

Who is it for? E-commerce product photography, quick compositing, batch background removal.


Matting Node (MEC)

Unified alpha matting with 7 backends. Takes a coarse mask and returns compositing-grade alpha.

BackendQualityRequiresBest for
vitmatte_small / vitmatte_base★★★★★transformersHair, fur, glass, transparency
matanyone2★★★★★Model downloadVideo matting, temporal consistency
rvm_mobilenetv3 / rvm_resnet50★★★★☆Model downloadReal-time video matting
cutie★★★★☆Model downloadVideo object cutout
sam_hq★★★☆☆Model downloadQuick high-quality mask
ParameterDefaultDescription
backendautoBackend selection (auto picks best available)
edge_radius15Trimap unknown-band width
erode_dilate0Pre-process mask morphology (−50 to +50)
n_warmup5Warmup frames for video backends

Outputs: rgb (premultiplied), alpha_mask


ViTMatte Edge Refiner (MEC)

Standalone edge refinement — feed any coarse mask and get clean edges.

MethodQualityRequiresBest for
vitmatte★★★★★transformersHair, fur, glass, complex edges
multi_scale_guided★★★★☆opencv-pythonGeneral high-quality
color_aware★★★★☆opencv-pythonChallenging lighting
guided_filter★★★☆☆opencv-pythonFast good-quality
laplacian_blend★★★☆☆opencv-pythonSmooth blending
gaussian_blur★★☆☆☆(none)Simple fallback

Trimap Generator (MEC)

Generates a 3-region trimap (white = foreground, black = background, gray = unknown) for ViTMatte input.

ParameterDefaultDescription
edge_radius15Width of the unknown boundary in pixels
inner_erosion1.0Foreground erosion scale (<1 tighter, >1 wider)
outer_dilation1.5Background dilation scale
smooth0.0Gaussian smoothing of boundaries
threshold0.5Binarization threshold

Outputs: trimap, foreground, unknown


Keying

Luminance Keyer (MEC)

Professional luminance keyer inspired by Nuke's LumaKeyer. Extracts a matte based on image brightness using ITU-R BT.709 luminance with smooth S-curve falloff and gamma correction.

How it works: Converts the image to BT.709 luminance (0.2126R + 0.7152G + 0.0722B), then applies a threshold range with Hermite smoothstep falloff. Five modes target different brightness ranges — auto mode analyzes the image and picks the best range automatically.

ParameterDefaultDescription
imageInput image(s) to key
modeautoauto / highlights (0.7–1.0) / midtones (0.3–0.7) / shadows (0.0–0.3) / custom
low0.0Low threshold (custom mode only)
high1.0High threshold (custom mode only)
gamma1.0Gamma correction — >1 shrinks mask, <1 expands
falloff1.0Edge smoothness — 0 = hard binary, 1 = smooth, >1 = very gradual
invertfalseFlip the mask

Outputs: mask, info (mode, thresholds, luminance stats, per-frame coverage)

Who is it for? VFX artists pulling luminance keys (sky replacement, highlight isolation, shadow grading), colorists building luminance-driven masks for selective color grading, anyone who needs brightness-based masking without a model.


Mask Editing & Transform

Mask Transform XY (MEC)

Independent per-axis mask manipulation: erode/expand, directional blur, offset, feather, threshold, invert.

ParameterDefaultDescription
expand_x / expand_y0Per-axis morphological expand (negative = erode)
blur_x / blur_y0.0Per-axis directional Gaussian blur
offset_x / offset_y0Translate mask in pixels
feather0.0Isotropic edge feathering
threshold0.0Binarization threshold (0 = disabled)
invertfalseInvert the mask

Mask Draw Frame (MEC)

Low-level shape drawing. Accepts a shape + JSON shape_params_json. Supports all 12 shapes (circle, rectangle, ellipse, polygon, line, triangle, star, diamond, cross, rounded_rectangle, heart, arrow) with SDF rendering, feathering, rotation, and blend operations.

Prefer Draw Shape (MEC) for new workflows — it exposes all parameters as named inputs instead of raw JSON.


Draw Shape (MEC) ★ New

Unified 12-shape drawing node with a single dropdown. All parameters are visible as named inputs with tooltips — irrelevant ones are ignored per shape. Replaces the 5 legacy per-shape wrapper nodes.

ParameterDefaultDescription
shapecircleDropdown: circle, rectangle, ellipse, polygon, line, triangle, star, diamond, cross, rounded_rectangle, heart, arrow
cx / cy256Center position (center-based shapes)
radius50Circle radius, triangle/heart size
size_w / size_h200 / 100Rectangle, rounded rect, diamond, arrow width/height
rx / ry100 / 50Ellipse radii
top_left_x / top_left_y100Rectangle/line start position
x2 / y2400Line end position
thickness5Line, cross thickness
outer_r / inner_r100 / 40Star radii
num_points5Star/polygon point count
corner_radius20Rounded rectangle corners
arrow_length / head_length / head_widthArrow dimensions
points_jsonPolygon vertices: [[x1,y1], ...]
value1.0Fill intensity
feather0.0Edge softness
rotation0.0Rotation in degrees
operationsetset / add / subtract / max / min
batch_size1Number of mask frames

Optional: coords_json (per-frame position override), existing_mask, reference_image

Output: mask (MASK)


Mask Composite Advanced (MEC)

Combine two masks with compositing operations.

OperationDescription
unionCombine both (max)
intersectOverlap only (min)
subtractA minus B
xorExclusive — one or the other, not both
blendWeighted average
min / maxPer-pixel min / max
differenceAbsolute difference

Automatically resizes masks to match if spatial dimensions differ.


Mask Math (MEC)

Mathematical operations on a single mask.

OperationDescription
add_scalarAdd constant value
multiply_scalarMultiply by value
powerRaise to power
invert1 − mask
clampClamp to [value_a, value_b] range
remap_rangeRemap from [value_a, value_b][0, 1]
quantizeSnap to N discrete levels
threshold_hysteresisDual-threshold with connected regions
gammaGamma correction
contrastContrast adjustment
abs_diff_from_valueAbsolute difference from value

All outputs are clamped to [0, 1].


Inpainting

Inpaint Crop Pro (MEC)

Crop image tightly around the mask region for focused inpainting, with separate inpaint and stitch blend masks. Feed the crop to any inpaint model, then stitch back seamlessly.

How it works: Computes tight bounding box around the mask, expands by context_expand, produces two separate masks — one for the inpaint model (crisp or feathered) and one for compositing back (Gaussian, edge-aware, Laplacian pyramid, or FFT frequency blend). Supports video-stable cropping (union bbox across all frames).

ParameterDefaultDescription
imageInput image batch
maskInpaint mask (white = area to inpaint)
context_expand1.5Crop expansion factor beyond mask bounds (1.0 = tight)
inpaint_mask_modehard_binaryWhat the model sees: hard_binary / slight_feather / soft_blend
stitch_blend_modegaussianCompositing mode: edge_aware / gaussian / laplacian_pyramid / frequency_blend
blend_radius32Feather radius for stitch blend mask
size_modefree_sizefree_size / forced_size (exact W×H) / ranged_size (min/max clamp)
forced_width / forced_height1024Target dimensions for forced_size mode
min_size / max_size512 / 2048Dimension clamp for ranged_size mode
padding_multiple8Pad output to be divisible by N
video_stable_cropfalseLock bbox across all frames for video consistency
fill_masked_areaedge_padFill masked area in crop: edge_pad / neutral_gray / original
downscale_methodlanczosInterpolation for downscaling: lanczos / bicubic / bilinear / nearest-exact / area
upscale_methodlanczosInterpolation for upscaling: same options

Outputs: stitch_data, cropped_image, inpaint_mask, stitch_blend_mask, crop_mask, cropped_composite, info

cropped_composite is a red-tinted debug preview showing the mask overlay on the crop — useful for verifying region coverage.

Who is it for? Inpainting power users who want crop → inpaint → stitch with professional blend modes (Laplacian pyramid, frequency blend, edge-aware).


Inpaint Composite (MEC) — unified Stitch + Paste Back

Single node that combines Inpaint Stitch Pro and Inpaint Paste Back behind one mode dropdown. The frontend hides parameters that don't apply to the current mode so the UI stays clean.

ParameterDefaultUsed in modeDescription
stitch_databothFrom Inpaint Crop Pro
inpainted_imagebothInpainted result from any model
modestitch_probothstitch_pro (advanced blend pipeline) or paste_back (clean resize + paste)
blend_mode_overridefrom_cropstitch_proOverride blend mode or keep what the crop node configured
color_matchfalsestitch_proReinhard mean+std color transfer before blending
upscale_methodlanczospaste_backResize interpolation for the inpainted crop
feather_edgesfalsepaste_backGaussian-feather the paste-rect boundary
feather_radius16paste_backFeather radius in pixels (0 disables)

Outputs: image, mask, info

  • In stitch_pro mode mask is the actual blend mask used (Laplacian / edge-aware / FFT etc).
  • In paste_back mode mask is the paste rectangle (feathered if enabled), so downstream nodes always get a usable mask.

When to use which mode

ModeUse when…
stitch_proYou want pro-level seam-hiding (Laplacian pyramid, edge-aware, FFT frequency blend). Slightly heavier.
paste_backYou just want a clean resize + paste (optionally feathered). Faster, deterministic, no blend pipeline.

Backward compatibility: the legacy Inpaint Stitch Pro (MEC) and Inpaint Paste Back (MEC) nodes are still registered (now labelled "legacy") so existing workflows keep working. New workflows should use Inpaint Composite (MEC).


Inpaint Stitch Pro (MEC) — legacy, prefer Inpaint Composite

Composite inpainted image back into the original using stitch data from Inpaint Crop Pro.

How it works: Takes the inpainted result and the stitch data, resizes and places it back at the original crop location, blending using the stored blend mask. Optional mean+std color matching reduces color shift at boundaries.

ParameterDefaultDescription
stitch_dataFrom Inpaint Crop Pro
inpainted_imageInpainted result from any model
blend_mode_overridefrom_cropOverride blend mode or keep original
color_matchfalseApply mean+std color transfer before stitching

Outputs: image, blend_mask_used, info


Inpaint Mask Prepare (MEC)

Standalone mask cleanup and dual-mask preparation for inpainting workflows.

How it works: Fills holes, removes small disconnected blobs, dilates the mask, then produces two outputs — a clean inpaint mask (for the model) and a stitch blend mask (for compositing). Optional temporal smoothing for video batch consistency.

ParameterDefaultDescription
maskRaw input mask
fill_holestrueFill interior holes
remove_small_regionstrueRemove disconnected blobs
min_region_area100Minimum region area in pixels
grow_pixels4Dilate mask by N pixels
inpaint_edge_modehard_binaryhard_binary / slight_feather
stitch_edge_modegaussiangaussian / edge_aware
stitch_feather_radius16Feather radius for stitch blend
temporal_smoothfalseGaussian smoothing along batch dimension
temporal_sigma1.5Temporal smoothing sigma (frames)
reference_image(optional)For edge-aware stitch blend

Outputs: inpaint_mask, stitch_blend_mask, debug_preview, info


Inpaint Paste Back (MEC) — legacy, prefer Inpaint Composite

Simple paste-back node: resize the inpainted crop and composite it onto the original with optional Gaussian-feathered alpha blending.

ParameterDefaultDescription
stitch_dataFrom Inpaint Crop Pro
inpainted_imageInpainted result from any model
feather_edgestrueGaussian-feathered alpha blending at crop boundary
feather_radius8Blur radius for edge feathering (pixels)

Outputs: image, info

Paste Back vs Stitch Pro vs Composite: All three live in the same suite. The new Inpaint Composite (MEC) node merges Stitch Pro and Paste Back behind one mode dropdown — prefer it for new workflows. The two legacy nodes remain for backward compatibility.


Image Comparer (MEC)

Interactive before/after comparison widget with 3 modes: drag-slider split, overlay blend, and difference heatmap.

ParameterDefaultDescription
image_aLeft / "before" image
image_bRight / "after" image
label_a"Before"(optional) Label for image A
label_b"After"(optional) Label for image B

Modes: ◧ Compare (drag slider) · ⊕ Overlay (alpha blend) · ≠ Diff (heatmap)

Who is it for? Quick visual comparison of before/after results — inpainting QA, model comparison, parameter tuning.


Batch & Video

Mask Batch Manager (MEC)

Manipulate mask batches for video workflows.

OperationDescription
sliceExtract frame range [start:end]
pick_framesSelect specific frames by index
repeatRepeat mask N times
reverseReverse frame order
concatJoin two mask batches
interleaveAlternate frames from two batches
insertInsert mask_b at position
removeRemove frame at index

Mask Propagate Video (MEC)

Draw mask on frame 1 → propagate across all frames.

ModeDescription
staticSame mask on every frame
fadeLinear fade to zero
scale_linearLinear scale over time
optical_flowTrack mask using optical flow
sam2_videoUse SAM2 video predictor for tracking

Temporal Anchor System (MEC)

Mask interpolation over time using Signed Distance Fields (SDF). Define masks on a few key frames and let the node smoothly morph between them across the full video.

How it works: Computes an SDF for each anchor mask (distance from boundary, negative inside, positive outside), then interpolates the SDF fields between anchor frames using configurable easing. The zero-crossing of the blended SDF produces the interpolated mask boundary. Optional optical flow refinement (Farneback or FFT phase correlation) warps the SDF to follow motion.

ParameterDefaultDescription
anchor_masksOne mask per anchor frame (A, H, W)
anchor_frames"0"Comma-separated frame indices (e.g. "0,10,30")
total_frames30Total output frames
easingsmooth_steplinear / ease_in / ease_out / smooth_step
sdf_iterations64SDF diffusion iterations (more = more accurate)
flow_refinementfalseEnable optical flow refinement
images(optional)Video frames for optical flow estimation

Outputs: full_masks (total_frames × H × W), confidence (per-frame float list), info

Who is it for? Video editors who need smooth mask morphing between keyframes — rotoscoping helpers, animated mask transitions, temporal mask interpolation where SAM tracking is overkill.


Video Frame Extractor (MEC)

Extract a single frame from a video batch.

ParameterDefaultDescription
modefirstfirst / last / middle / specific_frame
frame_index0Frame index for specific_frame mode (clamped to batch size)

Outputs: frame (IMAGE), total_frames (INT), is_video (BOOLEAN)


BBox Tools

Six nodes for bounding box manipulation:

NodeDescription
BBox CreateManual [x, y, width, height] entry
BBox From MaskExtract tight bbox from non-zero mask pixels with per-axis padding
BBox To MaskConvert bbox to a rectangular mask
BBox PadAsymmetric padding (top/bottom/left/right) with canvas clamping
BBox CropCrop image + mask to bbox region
BBox Smooth TemporalSmooth bbox sequences across video frames (moving-average / exponential)

All BBox nodes clamp outputs to valid canvas bounds — no negative dimensions, no out-of-bounds errors.


Diagnostics

Mask Failure Explainer (MEC)

Diagnose why a mask failed and get actionable fix suggestions. Pure tensor analysis — no models, no VRAM.

How it works: Runs a 5-metric analysis pipeline on your image + mask pair:

MetricWhat it measuresFailure threshold
BrightnessBT.709 mean luminanceDark scene < 0.15
BlurLaplacian variance × 1000Blurry image < 50
Boundary contrastStd deviation at mask edge ringLow contrast < 0.05
Color confusionMean color distance inside vs. outside maskHigh confusion < 0.1
Background complexitySobel edge density outside maskBusy background > 0.3

Each metric contributes up to 20 points to a severity score (0–100). The node outputs a human-readable explanation, a problem-regions heatmap, the severity score, and a suggested method (e.g. "try ViTMatte for complex edges" or "use BiRefNet for busy backgrounds").

ParameterDefaultDescription
imageInput image(s)
maskMask to diagnose
ring_width5Boundary ring width for contrast analysis
blur_threshold50.0Laplacian variance threshold
brightness_threshold0.15Dark scene threshold

Outputs: explanation (text), problem_regions_mask (heatmap), severity_score (0–100), suggested_method (string)

Who is it for? Anyone whose mask looks wrong and doesn't know why. Plug in your image + bad mask, read the diagnosis, follow the suggestion. Especially useful for beginners learning which segmentation method works for which scenario.


Interactive Editor

Points Mask Editor (MEC)

Full-featured interactive canvas editor for placing points and bounding boxes directly on your image.

ActionEffect
Left clickAdd positive point (foreground)
Right clickAdd negative point (background)
CTRL + Left dragDraw positive bounding box (green)
CTRL + Right dragDraw negative bounding box (red)
Shift + ClickDelete element under cursor
Scroll wheelAdjust point radius
CTRL + ScrollZoom in/out
Middle mouse dragPan canvas
Delete / BackspaceDelete hovered element
CTRL + Z / CTRL + Shift + ZUndo / Redo
RReset view

Toolbar: Pill counters for +pts / −pts / bbox count / radius. Buttons for ✕ Pts, ✕ BBox, ✕ All, ↶ Undo / Redo ↷, ▣ Fit.

Outputs (8):

OutputTypeDescription
maskMASKRendered points/bboxes mask
positive_coordsSTRING[{"x":int,"y":int}, ...] for SAM
negative_coordsSTRING[{"x":int,"y":int}, ...] for SAM
bboxesBBOXPositive bounding boxes
neg_bboxesBBOXNegative bounding boxes (SAM3)
points_jsonSTRINGFull point data for SAM Mask Generator
bbox_jsonSTRINGPrimary bbox for SAM Mask Generator
primary_bboxBBOX[x,y,w,h] for BBox pipeline

Connect a reference_image to see it as the editor background for precise placement.


Spline Mask Editor (MEC) ★ New

Interactive canvas for drawing spline-based masks directly on your image. Supports Catmull-Rom (smooth curves through points), Bezier (with tangent handles), and polyline (straight segments) modes.

ActionEffect
Left clickAdd control point (or close path by clicking first point)
Shift + clickDelete point under cursor
Ctrl + clickInsert point on nearest curve segment
Right-clickContext menu (Delete Point, Open/Close, Smooth/Sharp)
S keyToggle smooth / sharp interpolation for current path
Scroll wheelZoom in/out
Middle mouse dragPan canvas

Key improvements: Normalized [0,1] coordinates (resolution-independent), zoom-relative point sizes, segment insertion, close-by-clicking-first-point affordance (highlighted orange), property-based persistence.

ParameterDefaultDescription
spline_typecatmull_romcatmull_rom / bezier / polyline
closedtrueClose the spline loop for filled region
smoothingtrueEnable spline smoothing
samples_per_segment20Curve resolution (higher = smoother)
feather_radius0.0Gaussian edge softness
invertfalseFill outside spline instead of inside

Outputs: mask (MASK), coords_json (SAM-compatible points), spline_data_out (for Motion Mask Tracker)


Motion Mask Tracker (MEC) ★ New

Per-frame motion detection with 4 independent methods and camera stabilization. Feed a video batch — get a motion mask highlighting what moved between frames.

MethodDescription
pixel_diffAbsolute per-pixel brightness change
optical_flowFarneback dense flow or phase correlation
background_subStatic background model from first N frames
histogram_diffPer-region color histogram distance
ParameterDefaultDescription
camera_compensationtrueSubtract global camera motion (homography/affine/translation)
detection_modecombinedcombined / individual method
combine_methodunionunion (any triggers) / intersection (all agree)
grow_pixels4.0Expand detected regions
min_region_size100Remove noise regions < N pixels
temporal_smoothtrueGaussian smoothing across frames

Outputs: motion_mask (MASK), motion_intensity (FLOAT), info (STRING)

Who is it for? Video editors who need automatic motion masks for selective effects, stabilization-aware change detection, or motion-triggered workflows.


Preview

Video Frame Player (MEC)

In-graph video scrubber with drag-crop overlay, trim range, frame stride, lanczos resize, and upscale — all in one node so you don't have to chain Load → Trim → Crop → Resize → Preview. Plays inside the node, supports play/pause + ping-pong loop + I/O hotkeys (mark IN/OUT), and emits the trimmed/cropped/resized batch ready to feed a sampler.

GroupHighlights
Sourceframes, frame_index, output_mode (current_frame / all_frames)
Trim & playbackframe_start/frame_end (drag green/red markers on the timeline), frame_stride (orange ticks), playback_fps, loop_mode (once/loop/ping-pong)
Cropcrop_enabled, crop_locked, aspect_ratio (free / 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 2:1 / 21:9 / original / custom), crop_x/y/w/h set by drag overlay (8 handles + interior move, dim outside, rule-of-thirds guides, live W×H readout)
Resizeresize_method (none / lanczos / bicubic / bilinear / area / nearest-exact), target_width, target_height, upscale_factor
Outputsframe, frame_index, frame_count, processed, out_width, out_height, crop_x_px, crop_y_px, crop_w_px, crop_h_px, trimmed_count, playback_fps

Hotkeys (canvas focused): Space play/pause, ←/→ step ±1 (Shift = ±10), Home/End jump to trim bounds, I/O mark IN/OUT at current frame, R reset crop to full frame.

Full parameter table, pipeline order, and recipes (TikTok 9:16, half-rate stride, 2× lanczos upscale, hero-frame img2img): see docs/video-frame-player.md.


Mask Preview Overlay (MEC)

Visualize masks with 5 display modes:

ModeDescription
overlayRed-tinted mask overlaid on the image
binary_maskBlack & white mask only
edge_onlyShow mask edges / contours
side_by_sideOriginal image next to masked version
alpha_channelRGBA with alpha from mask

Handles batch size mismatches automatically (expands or repeats to match).


Utilities

Universal Reroute / Dot (MEC)

Nuke-style reroute dot that accepts any connection type (IMAGE, MASK, LATENT, STRING, INT, FLOAT, etc.). Use it to keep your workflow wires clean and organized.

Parameter History (MEC)

Tracks every parameter change across ComfyUI runs in a local SQLite database. Query with:

ModeDescription
all_historyFull parameter history for last N runs
last_run_diffWhat changed between the last two runs
node_class_filterFilter history by node class name

FolderIncrementer

Filesystem-aware auto-versioning for output files.

NodeDescription
Folder Version IncrementerScans output directory for v001, v002, … and returns the next available version
Folder Version CheckReports how many versions exist
Folder Version SetReserves version slots by creating placeholder directories

Key features:

  • Filesystem-based — no global counter file; scans the actual directory
  • Cancel-safe — if you cancel mid-execution, no version is wasted
  • Extension-preservingphoto.pngphoto/v001/photo.png
  • Optional suffix — set the new suffix widget (e.g. _Inpaint) and the basename of filename_prefix / output_filename becomes photo_Inpaint (folder + version_string are unchanged). No more downstream Concatenate nodes just to tag a pass.

Outputs:

OutputExamplePurpose
version_stringv001Version tag
version_number1Integer version
folder_namephotoDerived from source filename
subfolder_pathphoto/v001For Save Image subfolder
filename_prefixphoto/v001/photoWithout extension
output_filenamephoto/v001/photo.pngFull output path

Node Quick-Reference Table

All 47 nodes at a glance:

#NodeCategoryVRAM TierWhat it does
1SAM Model LoaderSAM2Load SAM 2.1 / SAM 3 checkpoints
2SAM Mask GeneratorSAM2SAM inference with point + bbox prompts
3SAM Multi-Mask PickerSAM2View all 3 SAM candidates, pick interactively
4Unified SegmentationSAM2One-node dispatcher for all segmentation backends
5SAM + ViTMatte PipelineSAM / Matting2SAM → refinement → ViTMatte end-to-end
6SeC + MatAnyone2 PipelineSAM / Matting3SeC → MatAnyone2 temporal video pipeline
7Semantic SegmentSegmentation2SegFormer face/body/clothes parsing
8Background RemoverMatting2One-click RMBG / BiRefNet removal
9Matting NodeMatting2Unified 7-backend alpha matting
10ViTMatte Edge RefinerMatting2Standalone edge refinement (7 methods)
11Trimap GeneratorMatting1Generate trimap for ViTMatte input
12Luminance KeyerKeying1BT.709 luminance keying with smoothstep
13Mask Transform XYEditing1Per-axis erode/expand/blur/offset
14Mask Draw FrameEditing1Draw 12 shapes with rotation and SDF
15Draw ShapeEditing1Unified 12-shape dropdown with all params — replaces per-shape wrappers
16Mask Composite AdvancedEditing1Boolean/blend two masks (8 operations)
17Mask MathEditing1Mathematical mask operations (11 ops)
18Spline Mask EditorInteractive1Interactive Catmull-Rom / Bezier / polyline spline drawing on canvas
19Inpaint Crop ProInpaint1Crop around mask for inpainting
20Inpaint CompositeInpaint1Unified Stitch Pro + Paste Back (mode dropdown)
20aInpaint Stitch Pro (legacy)Inpaint1Composite inpainted result back
21Inpaint Paste Back (legacy)Inpaint1Simple paste-back with feathered alpha
22Inpaint Mask PrepareInpaint1Clean + dual-mask preparation
23Image ComparerPreview1Interactive before/after comparison (3 modes)
24Mask Batch ManagerVideo1Slice/concat/interleave mask batches
25Mask Propagate VideoVideo1–2Propagate mask across video frames
26Temporal Anchor SystemVideo2SDF-based mask interpolation between keyframes
27Motion Mask TrackerVideo1Per-frame motion detection (4 methods, camera stabilization)
28Video Frame ExtractorVideo1Extract single frame from batch
29BBox CreateBBox1Manual bbox entry
30BBox From MaskBBox1Extract bbox from mask
31BBox To MaskBBox1Convert bbox to mask
32BBox PadBBox1Asymmetric bbox padding
33BBox CropBBox1Crop image + mask to bbox
34BBox Smooth TemporalBBox1Smooth bbox sequences across video frames
35Mask Failure ExplainerDiagnostics1Diagnose bad masks, suggest fixes
36Points Mask EditorInteractive1Canvas editor for points/bboxes
37Mask Preview OverlayPreview15-mode mask visualization
38Universal Reroute / DotUtility1Any-type wire reroute
39Parameter HistoryUtility1Track parameter changes over runs
40Folder Version IncrementerOutput1Auto-versioned file output
41Folder Version CheckOutput1Check existing versions
42Folder Version SetOutput1Reserve version slots
43–47Draw Circle / Rectangle / Ellipse / Polygon / LineEditing1(Deprecated) Legacy per-shape wrappers — use Draw Shape instead
48VAE MergeVAE1Merge 2/3 VAEs (8 algorithms, per-block alpha)
49VAE Latent InspectorVAE1Per-channel stats, NaN/Inf checks, health verdict
50VAE Similarity AnalyserVAE1Cosine similarity (global + per-block) between two VAEs
51VAE Block InspectorVAE1Per-block weight stats for a single VAE
52Color Space ConvertColor1sRGB ↔ linear ↔ Rec.709 ↔ ACEScg
53LUT Apply (.cube)Color1Adobe .cube 1D/3D LUT with strength blend
54Exposure GradeColor1Stops + WB temp/tint + contrast pivot
55Load EXRI/O1OpenEXR → imageio → TIFF fallback
56Save EXRI/O1Half-float by default, TIFF fallback
57EXR Metadata ReaderI/O1Pure-python header parser (no OpenEXR needed)
58Merge Render PassesRender1Beauty + diffuse/spec/emission/AO compositing
59Depth-of-Field MaskRender1Depth pass → CoC alpha mask
60Depth WarpGeometry1Horizontal parallax warp from depth
61Normal → CurvatureGeometry1Curvature mask from a tangent-space normal pass
62Position Pass SplitterGeometry1Split position pass into X/Y/Z masks
63Grain MatchPlate1Extract grain from reference plate, re-apply to target
64Plate StabilizerPlate1ORB+RANSAC affine (cv2) → FFT translation fallback
65Clean Plate ExtractorPlate1Median across batch with optional mask exclusion
66Difference MattePlate1L1/L2 image diff → MASK with threshold + softness
67Metadata WriterMetadata1Write/merge JSON sidecars next to outputs
68Frame Range RouterMetadata1Slice IMAGE/MASK batches [start:end:step]
69Shot Metadata ReaderMetadata1Read shot.json (show / shot / task / frame in/out / fps)
70Batch Version ManagerOutput1<root>/<show>/<shot>/<task>/v###/ with atomic reservation
71Temporal Consistency CheckerDiagnostics1Flicker score (mask_iou / pixel_diff / Farneback flow)
72Model Metadata ExtractorDiagnostics1Inspect safetensors/checkpoints without unpickling

VRAM Tiers: 1 = pure tensor math (CPU/GPU, no models), 2 = loads a model (~1–4 GB), 3 = loads multiple models


Workflows

Best Quality Masking (Single Image)

[SAM Model Loader]          [Load Image]
  offload_to_cpu: true         ↓
  dtype: float16          [Points Mask Editor]
        ↓                    ↓ points_json, bbox_json
[SAM + ViTMatte Pipeline] ←─┘
  sam_iterations: 2–3
  refine_method: auto
  detail_preservation: 0.85
  edge_contrast: 1.2
        ↓
  refined_mask → compositing

Fast Iteration

[SAM Mask Generator]  →  [ViTMatte Edge Refiner]
  refine_iterations: 2       method: multi_scale_guided

Pick the Best SAM Mask

[Load Image]  →  [Points Mask Editor]  →  [SAM Multi-Mask Picker]
                                              ↓ click thumbnail
                                         selected_mask → downstream

Inpaint Pipeline

[Load Image] + [Mask]  →  [Inpaint Crop Pro]     →  [Any Inpaint Model]
                              context_expand: 1.5        ↓
                              stitch_blend: edge_aware   [Inpaint Stitch Pro]
                                    ↓ stitch_data ──────→     ↓
                                                         seamless result

Video Masking

[Load Video]  →  [Video Frame Extractor]  →  [Points Mask Editor]
                   mode: first                      ↓
                                            [SAM Mask Generator]
                                                    ↓
                                            [Mask Propagate Video]
                                              mode: sam2_video
                                                    ↓
                                              per-frame masks

Temporal Mask Morphing

[Define masks on frames 0, 15, 30]  →  [Temporal Anchor System]
                                          anchor_frames: "0,15,30"
                                          total_frames: 60
                                          easing: smooth_step
                                                ↓
                                          60 interpolated masks

Alpha Matting (From Any Coarse Mask)

[Any Segmentation Node]  →  [Matting Node]
                               backend: auto
                               edge_radius: 15
                                    ↓
                              alpha_mask → compositing

Diagnose a Bad Mask

[Load Image] + [Bad Mask]  →  [Mask Failure Explainer]
                                    ↓
                              explanation: "Dark scene (mean=0.12), low boundary contrast"
                              suggested_method: "Try ViTMatte with edge_radius=20"
                              severity: 65/100

Luminance Keying

[Load Image]  →  [Luminance Keyer]
                    mode: auto
                    falloff: 1.0
                    gamma: 1.0
                       ↓
                  luminance mask (highlights / shadows / midtones)

SeC + MEC (Video Object Segmentation)

SeC handles tracking, MEC handles edge quality:

[SeC Video Segmentation]  →  [ViTMatte Edge Refiner (MEC)]  →  refined masks

Install SeC: cd ComfyUI/custom_nodes && git clone https://github.com/9nate-drake/Comfyui-SecNodes

Spline Mask Drawing

[Load Image]  →  [Spline Mask Editor]
                    spline_type: catmull_rom
                    closed: true
                    feather_radius: 2.0
                       ↓
                  mask → any mask input
                  coords_json → SAM Mask Generator
                  spline_data → Motion Mask Tracker

Motion Detection (Video)

[Load Video Frames]  →  [Motion Mask Tracker]
                           camera_compensation: true
                           detection_mode: combined
                           grow_pixels: 4
                                ↓
                          motion_mask → compositing / routing
                          motion_intensity → Switch node

Draw Shape (Quick Masking)

[Draw Shape (MEC)]
   shape: star
   cx: 256, cy: 256
   outer_r: 100, inner_r: 40
   num_points: 5
   feather: 4.0
        ↓
   mask → downstream

VRAM Management

All nodes are designed to work on low-end GPUs (4–6 GB VRAM):

  • VRAM monitoring — model loading logs a warning when free VRAM drops below 2 GB
  • OOM recovery — if GPU runs out of memory, nodes fall back to CPU instead of crashing
  • Offload to CPU — SAM Model Loader has offload_to_cpu to keep models in system RAM
  • Auto memory cleanup — all nodes run gc.collect() + torch.cuda.empty_cache() in finally blocks
  • dtype control — use float16 or bfloat16 to halve VRAM usage
  • Torch-only fallbacks — if opencv-python is not installed, all nodes fall back to pure PyTorch implementations (slightly slower but functional)
  • VRAM tiers — each node declares its tier (1 = no model, 2 = one model, 3 = multiple models) so you can plan your workflow

Running Tests

The test suite covers all pure-tensor nodes (no GPU models required):

# Run all tests:
python -m pytest tests/ -v --tb=short

# Run a specific node's tests:
python -m pytest tests/test_luminance_keyer.py -v
python -m pytest tests/test_inpaint_suite.py -v
python -m pytest tests/test_mask_failure_explainer.py -v
python -m pytest tests/test_temporal_anchor.py -v
python -m pytest tests/test_sam_multi_mask_picker.py -v

Troubleshooting

ProblemSolution
ModuleNotFoundError: cv2pip install opencv-python>=4.7.0 — nodes will use torch fallbacks but cv2 gives better quality
ModuleNotFoundError: transformerspip install transformers pillow — only needed for ViTMatte matting
Torch version mismatch after pip install -r requirements.txtReinstall your ComfyUI torch: check PyTorch install page for your CUDA version
SAM model not foundPlace .pth / .pt / .safetensors in ComfyUI/models/sams/ or ComfyUI/models/sam2/
CUDA out of memoryEnable offload_to_cpu in SAM Model Loader, use float16 dtype, reduce image resolution
Nodes not showing in menuCheck console for [MEC] Loaded 44 message. If missing, check for import errors in the console output
ViTMatte download failsDownload manually from HuggingFace → place in ComfyUI/models/vitmatte/
My mask looks badConnect your image + mask to Mask Failure Explainer — it will diagnose the issue and suggest the right method

Project Structure

ComfyUI-CustomNodePacks/
├── __init__.py                     # Node registration (47 nodes)
├── folder_incrementer.py           # FolderIncrementer nodes (3)
├── conftest.py                     # Pytest root configuration
├── pyproject.toml                  # Package metadata
├── requirements.txt                # Dependencies
├── js/
│   ├── folder_incrementer.js       # Frontend: FolderIncrementer
│   ├── image_comparer.js           # Frontend: before/after comparison widget
│   ├── points_bbox_editor.js       # Frontend: interactive canvas editor
│   ├── parameter_memory.js         # Frontend: parameter history UI
│   ├── sam_multi_mask_picker.js    # Frontend: 3-mask thumbnail picker
│   ├── spline_mask_editor.js       # Frontend: spline drawing canvas (normalized coords)
│   └── universal_reroute.js        # Frontend: Nuke-style dot
├── nodes/
│   ├── sam_model_loader.py         # SAM 2.1 / SAM 3 model loader
│   ├── sam_mask_generator.py       # SAM inference engine
│   ├── sam_multi_mask_picker.py    # Multi-mask picker + JS widget
│   ├── sam_vitmatte_pipeline.py    # SAM → ViTMatte end-to-end pipeline
│   ├── sec_matanyone_pipeline.py   # SeC → MatAnyone2 video pipeline
│   ├── unified_segmentation_node.py# Unified segmentation dispatcher
│   ├── unified_segmentation.py     # Segmentation backends (deprecated)
│   ├── semantic_segment.py         # SegFormer face/clothes parsing
│   ├── background_remover.py       # RMBG / BiRefNet background removal
│   ├── matting_node.py             # 7-backend alpha matting
│   ├── vitmatte_refiner.py         # Standalone edge refiner
│   ├── trimap_generator.py         # Trimap generation
│   ├── luminance_keyer.py          # BT.709 luminance keyer
│   ├── mask_transform_xy.py        # Per-axis mask transform
│   ├── mask_draw_frame.py          # Shape drawing (12 shapes + DrawShapeMEC unified node)
│   ├── mask_composite.py           # Mask compositing ops
│   ├── mask_math.py                # Mathematical mask ops
│   ├── mask_batch_manager.py       # Batch manipulation
│   ├── mask_propagate_video.py     # Video mask propagation
│   ├── mask_preview.py             # Mask visualization
│   ├── mask_failure_explainer.py   # Mask diagnostics engine
│   ├── temporal_anchor.py          # SDF interpolation system
│   ├── inpaint_suite.py            # Crop/stitch/paste-back/prepare (4 nodes)
│   ├── bbox_nodes.py               # BBox tools (6 nodes incl. BBoxSmooth)
│   ├── points_mask_editor.py       # Interactive point/bbox editor
│   ├── spline_mask_editor.py       # Interactive spline mask drawing
│   ├── motion_mask_tracker.py      # Per-frame motion detection (4 methods)
│   ├── stabilization_utils.py      # Camera stabilization helpers
│   ├── video_frame_extractor.py    # Frame extraction
│   ├── image_comparer.py           # Before/after image comparison
│   ├── universal_reroute.py        # Nuke-style reroute dot
│   ├── parameter_memory.py         # Parameter history + SQLite
│   ├── model_manager.py            # Shared model cache & download
│   └── utils.py                    # Shared utilities
├── docs/
│   ├── inpaint-suite.md            # Inpaint Crop/Stitch/Paste Back/Prepare
│   ├── mask-editing.md             # Transform, Draw, Composite, Math, Batch, Preview
│   ├── sam-segmentation.md         # SAM, Unified Segmentation, Pipelines
│   ├── matting-refinement.md       # Matting, ViTMatte, Trimap, Keyer
│   ├── video-temporal-bbox.md      # Video, Temporal Anchor, BBox tools
│   └── utility-nodes.md            # Editor, Comparer, Diagnostics, Utils
├── tests/
│   ├── test_luminance_keyer.py     # 38 tests
│   ├── test_inpaint_suite.py       # Inpaint suite tests
│   ├── test_mask_failure_explainer.py # Diagnostics tests
│   ├── test_temporal_anchor.py     # Temporal anchor tests
│   └── test_sam_multi_mask_picker.py  # Multi-mask picker tests
├── example_workflows/
│   ├── basic_sam_segmentation.json
│   ├── sam_vitmatte_pipeline.json
│   ├── mask_editing_toolkit.json
│   ├── bbox_pipeline.json
│   └── video_mask_propagation.json
└── third_party/                    # Reference implementations

Acknowledgements

This project builds on or references the following open-source work:

ProjectAuthorLicenseDescription
Segment AnythingMeta AIApache-2.0SAM foundation model
Segment Anything 2Meta AIApache-2.0SAM2 / SAM2.1 video segmentation
SAM-HQSysCV (ETH Zurich)Apache-2.0High-quality SAM variant (NeurIPS 2023)
ViTMatteHUST VLMITVision Transformer alpha matting
Matte-AnythingHUST VLMITInteractive SAM + matting pipeline
MatAnyone2NTU S-LabS-Lab-1.0Video matting with learned quality evaluator
RobustVideoMattingPeterL1n / ByteDanceGPL-3.0Real-time human video matting
CutiehkchengrexMITVideo object segmentation (CVPR 2024)
ComfyUI-segment-anything-2kijaiApache-2.0SAM2 ComfyUI nodes with points editor
ComfyUI-SecNodes9nate-drakeApache-2.0SeC 4B video segmentation nodes
ComfyUI-MatAnyoneFuouMMITMatAnyone ComfyUI wrapper
ComfyUI-RMBG1038labGPL-3.0RMBG-2.0 / BiRefNet background removal
ComfyUI-KJNodeskijaiGPL-3.0Utility node collection
ComfyUI-Inpaint-CropAndStitchlquesadaGPL-3.0Crop-and-stitch inpainting reference
ComfyUI-VideoMaMaokdaltoVideoMaMa mask-guided video matting
ComfyUI LayerStylechflame163MITLayer compositing node suite
ComfyUI LayerStyle Advancechflame163MITAdvanced nodes (BiRefNet, Florence2, etc.)

License

MIT


Use in image/video generation pipelines (Flux / Qwen-Image / Wan / Z-Image / ERNIE-VL)

This umbrella pack aggregates ~72 nodes across four sub-namespaces — Folder Incrementer (_FOLDER_MAPPINGS, 3 nodes), MEC tools (_MEC_MAPPINGS, 30 nodes covering masking, SAM/ViT-Matte segmentation, inpaint crop/stitch/paste-back, spline editors, motion mask trackers, draw shapes, VAE merge/inspect, batch version manager, temporal consistency, model metadata, image comparer, parameter history, semantic segment, luminance keyer, mask failure explainer, temporal anchor, SAM multi-mask picker), Paint nodes (_PAINT_MAPPINGS), and MA nodes (_MA_MAPPINGS). The nodes are model-agnostic — they speak ComfyUI's native IMAGE, MASK, LATENT, VAE, and MODEL types — so they slot into any sampler graph regardless of which diffusion family produces the pixels.

Model familyRecommended bridges
FluxUse InpaintCropProMEC + InpaintStitchProMEC + InpaintPasteBackMEC to confine high-resolution Flux refinement to a tracked region. SAMViTMattePipelineMEC and TrimapGeneratorMEC produce the high-quality alpha that Flux-driven matte refinement needs. BatchVersionManagerMEC (combined with FolderIncrementer) keeps versioned outputs across sweeps. VAEMergeMEC / VAELatentInspectorMEC are useful when comparing Flux VAE variants.
Qwen-ImageIdentical inpaint and matte pattern as Flux. MaskTransformXY and MaskPropagateVideo are useful when reusing a single Qwen-Image generated mask across a small sequence. ImageComparerMEC for A/B sweeps over guidance / sampler choices.
Wan 2.x (video)MotionMaskTrackerMEC, MaskPropagateVideo, TemporalAnchorMEC, SeCMatAnyonePipelineMEC and TemporalConsistencyCheckerMEC are designed for the video domain — keep masks coherent across Wan-Animate frames, anchor a key-frame mask, and audit temporal jitter. MaskFailureExplainerMEC flags problem frames before re-rendering. Pair with ComfyUI-WanAnimatePreprocessV2 (human) or ComfyUI-WanAnimalPreprocess (animal) for the pose / face conditioning.
Z-ImageSame inpaint and refine bridges as Flux/Qwen. The spline-mask, draw-shape, and points-mask editors are useful when authoring a custom region for Z-Image's refinement passes.
GLM-ImageThe IMAGE outputs feed cleanly into the GLM-Image I2I path (via the sampler's optional image input + denoise_strength). BackgroundRemoverMEC + SAMMaskGeneratorMEC provide the alpha pre-stage.
ERNIE-VLNot applicable for sampling (ERNIE-VL is a multimodal LLM). The ModelMetadataExtractorMEC and ParameterHistoryMEC nodes can still be useful for cataloguing assets that ERNIE-VL has captioned.

Two general patterns recur across all sampler families:

  1. Inpaint trioInpaintCropProMEC → diffusion sampler (any family) → InpaintPasteBackMEC (or InpaintStitchProMEC for soft seams). Allows full-resolution refinement at a fraction of the VRAM, regardless of which model is loaded.
  2. Versioned saves — wire BatchVersionManagerMEC (or the standalone FolderIncrementer) version_string into the sampler's Save Image.filename_prefix so every queued prompt produces a clean, ordered file series.

The UniversalRerouteMEC-equivalent typed reroutes (and the SAM / ViT-Matte loaders) keep the graph readable as it scales from a single Flux T2I bench into a multi-model Wan + Qwen-refine + Flux-detail composite.


Made with ❤️ for the ComfyUI community


Full Node & Parameter Reference

A complete, auto-generated reference covering every node, return type and widget exposed by this pack lives in NODE_REFERENCE.md. It is regenerated whenever INPUT_TYPES change.

Contributors

Code2Collapse/ComfyUI-CustomNodePacks

Experimental nodes! This is a production suite for ComfyUI — SAM2.1/SAM3 segmentation, alpha matting, inpaint crop/stitch, VFX tools (EXR I/O, LUTs, render passes), video mask propagation, temporal anchors, VAE merging, spline editors, and auto-versioned output.

54

stars

555

commits

Python

primary language

Sep 10, 2026

updated

README

MEC Logo

📖 Full node & parameter reference

NODE_REFERENCE.md documents every node in this pack: each input's type, default, valid range and what it actually does, plus every output. It is generated directly from the live NODE_CLASS_MAPPINGS, so the descriptions there are the same strings you see as tooltips in ComfyUI and cannot drift out of date. Start there when you want to know what a knob does; read on here for how the pieces fit together.

ComfyUI-CustomNodePacks

MaskEditControl (MEC) + FolderIncrementer + VFX Suite
Production-grade mask editing, SAM1/2/3 segmentation, alpha matting, inpainting, diagnostics,
temporal mask interpolation, luminance keying, color science, EXR I/O, render-pass
compositing, plate tools, VAE merging & analysis, and auto-versioned file output for ComfyUI.

InstallationNode ReferenceWorkflowsTroubleshootingAcknowledgementsLicense


⚠️ Non-Commercial Model Notice: The RMBG-2.0 model weights (briaai/RMBG-2.0) are subject to the BRIA AI RMBG License, which restricts commercial use. If you use the Background Remover node with the rmbg_2.0 backend for commercial purposes you must obtain a commercial licence from Bria AI at https://bria.ai. All other models used in this pack (SAM, SAM2, BiRefNet, ViTMatte, SeC, etc.) are Apache-2.0 or MIT licensed and may be used commercially. See NOTICE.md for full attribution and license details.


Overview

ComfyUI-CustomNodePacks ships 72 nodes organized into the following packs:

PackNodesPurpose
MaskEditControl (MEC)33Pinpoint mask editing, SAM1/2/3 segmentation, SAM multi-mask picker, SeC + MatAnyone2 pipeline, background removal, face/clothes parsing, ViTMatte alpha matting, luminance keying, inpaint crop/stitch/paste-back suite, image comparison, mask failure diagnostics, temporal anchor interpolation, video propagation, compositing tools
VAE Tools4Merge two/three VAEs (8 algorithms, per-block alpha), latent inspector, similarity analyser, per-block weight inspector
VFX Suite19Color-space convert (sRGB/linear/Rec.709/ACEScg), .cube LUT apply, exposure/grade, EXR load+save, merge render passes, depth-of-field mask, depth warp, normal→curvature, position-pass splitter, grain match, plate stabilizer, clean-plate extractor, difference matte, metadata writer, frame-range router, shot-metadata reader
Diagnostics5EXR metadata reader, batch version manager, temporal consistency checker, model metadata extractor, parameter history
FolderIncrementer3Filesystem-safe auto-versioned output (v001, v002, …) with name sanitization and atomic version reservation
Universal Reroute1Nuke-style Dot node — reroute any wire type for cleaner workflow graphs
Parameter Memory1Tracks every parameter change with SQLite history, defaults recall, and per-run diffing

All nodes are prefixed with (MEC) in the ComfyUI node menu for easy discovery.

Who is this for?

  • VFX / compositing artists who need Nuke-quality mask control inside ComfyUI
  • Video creators who need temporally consistent masks across hundreds of frames
  • Inpainters who want crop → inpaint → stitch pipelines with edge-aware blending
  • Anyone tired of SAM giving 3 masks and not knowing which one to pick
  • Beginners who want one-click background removal or a node that tells them why their mask failed

Installation

1. Clone the repo

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

Or install via ComfyUI Manager → search "CustomNodePacks".

2. Install dependencies

⚠️ IMPORTANT: Check your existing package versions before installing.

ComfyUI bundles its own torch, torchvision, numpy, and Pillow. Blindly running pip install -r requirements.txt can overwrite them with incompatible versions and break your ComfyUI installation.

Recommended approach: Open requirements.txt, comment out anything already installed, and only install what you're missing:

# Check what you already have:
pip list | grep -i "opencv\|scipy\|safetensors\|transformers"

# Then install only what's missing:
pip install opencv-python>=4.7.0 scipy>=1.10.0 safetensors>=0.4.0

The requirements.txt lists:

PackageRequired?Purpose
opencv-pythonYesEdge detection, morphological ops, guided filter
scipyYesGaussian filters, signal processing
safetensorsYesSafe model weight loading
transformersOptionalViTMatte neural matting (best quality edges)
pillowOptionalImage I/O for ViTMatte

Core packages (torch, torchvision, numpy) are already provided by ComfyUI — do not reinstall them.

3. Place SAM model checkpoints

Download SAM 2.1 / SAM 3 weights and place them in:

ComfyUI/models/sams/        ← SAM 3
ComfyUI/models/sam2/        ← SAM 2.1
ModelFileSource
SAM2.1 Largesam2.1_hiera_large.ptMeta AI
SAM3sam3_hiera_large.ptMeta AI

The SAM Model Loader node auto-detects model type from the filename.

Note: Legacy SAM 1 (ViT-H/L/B) and the original SAM 2.0 line are no longer supported. Only SAM 2.1 and SAM 3 are exposed.

4. (Optional) ViTMatte matting

For the highest-quality edge refinement (hair, fur, glass, lace):

pip install transformers pillow

The ViTMatte model (~400 MB) auto-downloads from HuggingFace on first use. For offline setups, place model files in ComfyUI/models/vitmatte/.

5. Restart ComfyUI

Look for [MEC] Loaded 44 MaskEditControl nodes. in the console to confirm.


Detailed Documentation

📚 Start here: docs/README.md — the central documentation index with quick-nav by task, pack-by-pack reference, and image-vs-video pipeline guidance.

Every node's parameters, modes, and outputs are documented in depth in the docs/ folder:

GuideNodesWhat's inside
Documentation IndexCentral nav: quick lookup by task, pack-by-pack reference, image-vs-video helpers
Inpaint Suite4Crop Pro, Stitch Pro, Paste Back, Mask Prepare — full pipeline with fill modes, blend modes, interpolation methods
ProPainter Suite ★ new5Temporal video inpaint, stitch (drop-in for legacy), seam-only refine, model-free remove, RAFT flow refine
Face Fixer ★ new1YOLO11 face detection → per-face KSampler → smart blend with [SEP]/[ASC]/[DSC]/[SKIP] wildcard prompts
Paint Suite ★ new2Interactive paint canvas (hardness/expansion/blur stages) + smart context inpainter (color match, lightness rescue, differential diffusion)
Mask + Matting Pipeline ★ new1Combined MaskMattingMEC — pick segmenter (SAM2.1/SAM3/SeC/…) + matter (ViTMatte/RVM/MatAnyone2/…) + slot-based prompts
Video Stabilizer ★ new3Classic GFTT+LK / RAFT dense flow / auto-router with 4 presets; padding-mask output wires into Inpaint Crop Pro
Mask Editing8Transform XY, Draw Frame (12 shapes), Draw Shape (unified dropdown), Composite Advanced (8 ops), Math (11 ops), Batch Manager, Preview Overlay, Spline Mask Editor
SAM & Segmentation8Model Loader, Mask Generator, Multi-Mask Picker, Unified Segmentation, Semantic Segment, Background Remover, both pipelines
Matting & Refinement4Matting Node (7 backends), ViTMatte Refiner (7 methods), Trimap Generator, Luminance Keyer
Video, Temporal & BBox10Frame Extractor, Mask Propagate (5 modes), Temporal Anchor (SDF), Motion Mask Tracker (4 methods), 6 BBox nodes
Utility & Interactive8Points Mask Editor, Image Comparer, Mask Failure Explainer, Parameter History, Universal Reroute, 3 Folder Incrementer nodes
VAE Tools4VAE Merge (8 algorithms), Latent Inspector, Similarity Analyser, Block Inspector
Color Science3sRGB/linear/Rec.709/ACEScg convert, .cube LUT apply, exposure/WB/contrast grade
EXR I/O2Load and save OpenEXR with imageio + TIFF fallback chain
Render Passes2Merge beauty + AO/diffuse/spec/emission, depth→CoC mask
Plate Tools4Grain match, plate stabilizer (ORB/FFT), clean-plate extractor, difference matte
Video Frame Player1In-graph scrubber + drag-crop (8 handles, aspect-lock) + trim range + frame-stride + lanczos resize/upscale, all in one node

Node Reference

Legend

All nodes appear in the ComfyUI menu under MaskEditControl/ categories.

SymbolMeaning
★★★★★Best quality (may need optional deps)
★★★★☆Great quality
★★★☆☆Good / fast fallback

Segmentation & SAM

SAM Model Loader (MEC)

Loads SAM 2.1 / SAM 3 checkpoints with optional VRAM offload.

ParameterDefaultDescription
model_nameCheckpoint filename (auto-listed from models/sams/ and models/sam2/)
model_typeautoForce type: sam2.1, sam3, or auto
devicecudacuda / cpu
offload_to_cpufalseKeep model on CPU, move to GPU only during inference (saves ~2–4 GB VRAM)
dtypefloat16float16 / bfloat16 / float32

Output: SAM_MODEL — connect to SAM Mask Generator, SAM Multi-Mask Picker, or SAM + ViTMatte Pipeline.


SAM Mask Generator (MEC)

Runs SAM 2.1 / SAM 3 inference with point + bbox prompts, iterative refinement, and auto-negative point sampling.

ParameterDefaultDescription
imageInput image
sam_modelFrom SAM Model Loader
points_json""[{"x":int, "y":int, "label":1}, ...]
bbox_json""[x1, y1, x2, y2]
multimasktrueReturn 3 candidate masks
mask_index0Which candidate (0–2) to use
refine_iterations1Iterative SAM passes (each tightens boundaries)
auto_negative_points0Sample N negative points from outside the mask

Outputs: masks, best_score, info


SAM Multi-Mask Picker (MEC)

Run SAM inference and view all 3 candidate masks side-by-side with IoU scores. An interactive JS widget renders thumbnails — click a mask or press 1 / 2 / 3 to select it instantly.

How it works: SAM always outputs 3 masks ranked by confidence. Instead of guessing which mask_index is best, this node shows all three with quality scores and lets you pick visually. Works with SAM1, SAM2, and HQ-SAM.

ParameterDefaultDescription
imageInput image
model_nameSAM model (SAM1 / SAM2 / HQ-SAM, auto-listed)
points_json[{"x":256,"y":256,"label":1}]Point prompts JSON
bbox_json""Optional bounding box [x1,y1,x2,y2]
precisionfp32fp32 / fp16 / bf16
selected_index0Which candidate (0–2) — updated by widget click
sam_model(optional)Pre-loaded SAM model from SAM Model Loader
bbox(optional)BBox from BBox pipeline (overrides bbox_json)

Outputs: selected_mask, all_masks (3×H×W), selected_index, scores (JSON), info

Who is it for? When SAM gives you 3 options and you don't know which is best — see them all at once, pick with one click, and pipe the winner downstream.


Unified Segmentation (MEC)

One-node dispatcher for SAM 2.1, SAM 3, SeC, VideoMaMa with automatic image vs. video detection.

ParameterDefaultDescription
model_nameModel selector
points_json / bbox_json""Point and box prompts
precisionfp16fp16 / bf16 / fp32
attention_modeautosdpa / flash_attn / sage_attn / xformers
text_prompt(optional) Text prompt for grounding models

Outputs: masks, best_score, info


SAM + ViTMatte Pipeline (MEC)

End-to-end pipeline: SAM coarse segmentation → iterative refinement → neural alpha matting in a single node. Best possible masking quality for single images.

ParameterDefaultDescription
sam_iterations2Iterative SAM passes
refine_methodautoauto / vitmatte / multi_scale_guided / color_aware / laplacian_blend
edge_radius12Pixels around edges to refine
detail_preservation0.85Fine detail retention (hair, fur, lace)
edge_contrast1.0Edge sharpness boost (>1 = sharper)
fill_holestrueFill holes inside mask
remove_small_regions64Remove noise < N pixels

Outputs: refined_mask, coarse_mask, edge_mask, preview, detected_bbox, score, info

Pipeline stages:

  1. SAM coarse mask from point/bbox prompts
  2. Iterative refinement (re-run SAM with mask-derived prompts)
  3. Edge-aware matting (ViTMatte / guided filter / LAB color)
  4. Edge contrast boost
  5. Post-processing (hole fill, small region removal)

SeC + MatAnyone2 Pipeline (MEC)

End-to-end pipeline: SeC MLLM segmentation → MatAnyone2 temporal alpha matting in a single node. Best for video masking with temporal consistency.

ParameterDefaultDescription
segmentation_modelSeC / SAM2 / SAM3 model selector
text_prompt""Text description of target object (e.g. "cat", "person in red")
matting_backendautoauto / matanyone2 / vitmatte_small / vitmatte_base
edge_radius15Edge refinement radius in pixels
n_warmup5MatAnyone2 warmup frames (more = better temporal init)
edge_refine_methodnoneOptional post-matting refinement: vitmatte / guided_filter / multi_scale_guided
fill_holes_enabledtrueFill interior holes in alpha
min_region_size64Remove isolated regions < N pixels

Outputs: rgb (premultiplied), alpha_mask, coarse_mask, preview, info

Pipeline stages:

  1. SeC/SAM coarse segmentation (text or point/bbox prompts)
  2. MatAnyone2 temporal alpha matting with warmup protocol
  3. Optional edge refinement (ViTMatte / guided filter)
  4. Post-processing (hole fill, small region removal)

Key advantages over SAM + ViTMatte:

  • SeC uses a Vision-Language Model for semantic understanding (text prompts)
  • MatAnyone2 provides temporal consistency across video frames
  • Better for long sequences with occlusions and re-appearances

Semantic Segment (MEC)

Face / body / clothes semantic parsing using SegFormer. Select classes by name to build a combined mask.

ParameterDefaultDescription
model_namesegformer_face (19-class facial) or segformer_clothes (18-class apparel)
classes_csv"skin,hair"Comma-separated class names to include
threshold0.5Confidence threshold
invertfalseInvert output mask

Face classes: skin, l_brow, r_brow, l_eye, r_eye, eye_g, l_ear, r_ear, ear_r, nose, mouth, u_lip, l_lip, neck, necklace, cloth, hair, hat

Clothes classes: hat, hair, sunglasses, upper_clothes, skirt, pants, dress, belt, left_shoe, right_shoe, face, left_leg, right_leg, left_arm, right_arm, bag, scarf

Output: mask, info

Who is it for? Portrait retouchers who need to isolate specific facial features or clothing items without manual masking.


Alpha Matting

Background Remover (MEC)

One-click background removal using RMBG-2.0 or BiRefNet. Outputs a clean foreground and alpha mask.

ModelQualityBest for
rmbg_2.0★★★★☆General-purpose, fast
birefnet_general★★★★★High-detail edges
birefnet_portrait★★★★★Human portraits
ParameterDefaultDescription
model_nameBackground removal model selector
threshold0.5Alpha threshold (0 = soft, 1 = hard)
invertfalseKeep background instead
mask_blur0Gaussian blur on mask edges

Outputs: foreground (premultiplied RGB), mask, info

Who is it for? E-commerce product photography, quick compositing, batch background removal.


Matting Node (MEC)

Unified alpha matting with 7 backends. Takes a coarse mask and returns compositing-grade alpha.

BackendQualityRequiresBest for
vitmatte_small / vitmatte_base★★★★★transformersHair, fur, glass, transparency
matanyone2★★★★★Model downloadVideo matting, temporal consistency
rvm_mobilenetv3 / rvm_resnet50★★★★☆Model downloadReal-time video matting
cutie★★★★☆Model downloadVideo object cutout
sam_hq★★★☆☆Model downloadQuick high-quality mask
ParameterDefaultDescription
backendautoBackend selection (auto picks best available)
edge_radius15Trimap unknown-band width
erode_dilate0Pre-process mask morphology (−50 to +50)
n_warmup5Warmup frames for video backends

Outputs: rgb (premultiplied), alpha_mask


ViTMatte Edge Refiner (MEC)

Standalone edge refinement — feed any coarse mask and get clean edges.

MethodQualityRequiresBest for
vitmatte★★★★★transformersHair, fur, glass, complex edges
multi_scale_guided★★★★☆opencv-pythonGeneral high-quality
color_aware★★★★☆opencv-pythonChallenging lighting
guided_filter★★★☆☆opencv-pythonFast good-quality
laplacian_blend★★★☆☆opencv-pythonSmooth blending
gaussian_blur★★☆☆☆(none)Simple fallback

Trimap Generator (MEC)

Generates a 3-region trimap (white = foreground, black = background, gray = unknown) for ViTMatte input.

ParameterDefaultDescription
edge_radius15Width of the unknown boundary in pixels
inner_erosion1.0Foreground erosion scale (<1 tighter, >1 wider)
outer_dilation1.5Background dilation scale
smooth0.0Gaussian smoothing of boundaries
threshold0.5Binarization threshold

Outputs: trimap, foreground, unknown


Keying

Luminance Keyer (MEC)

Professional luminance keyer inspired by Nuke's LumaKeyer. Extracts a matte based on image brightness using ITU-R BT.709 luminance with smooth S-curve falloff and gamma correction.

How it works: Converts the image to BT.709 luminance (0.2126R + 0.7152G + 0.0722B), then applies a threshold range with Hermite smoothstep falloff. Five modes target different brightness ranges — auto mode analyzes the image and picks the best range automatically.

ParameterDefaultDescription
imageInput image(s) to key
modeautoauto / highlights (0.7–1.0) / midtones (0.3–0.7) / shadows (0.0–0.3) / custom
low0.0Low threshold (custom mode only)
high1.0High threshold (custom mode only)
gamma1.0Gamma correction — >1 shrinks mask, <1 expands
falloff1.0Edge smoothness — 0 = hard binary, 1 = smooth, >1 = very gradual
invertfalseFlip the mask

Outputs: mask, info (mode, thresholds, luminance stats, per-frame coverage)

Who is it for? VFX artists pulling luminance keys (sky replacement, highlight isolation, shadow grading), colorists building luminance-driven masks for selective color grading, anyone who needs brightness-based masking without a model.


Mask Editing & Transform

Mask Transform XY (MEC)

Independent per-axis mask manipulation: erode/expand, directional blur, offset, feather, threshold, invert.

ParameterDefaultDescription
expand_x / expand_y0Per-axis morphological expand (negative = erode)
blur_x / blur_y0.0Per-axis directional Gaussian blur
offset_x / offset_y0Translate mask in pixels
feather0.0Isotropic edge feathering
threshold0.0Binarization threshold (0 = disabled)
invertfalseInvert the mask

Mask Draw Frame (MEC)

Low-level shape drawing. Accepts a shape + JSON shape_params_json. Supports all 12 shapes (circle, rectangle, ellipse, polygon, line, triangle, star, diamond, cross, rounded_rectangle, heart, arrow) with SDF rendering, feathering, rotation, and blend operations.

Prefer Draw Shape (MEC) for new workflows — it exposes all parameters as named inputs instead of raw JSON.


Draw Shape (MEC) ★ New

Unified 12-shape drawing node with a single dropdown. All parameters are visible as named inputs with tooltips — irrelevant ones are ignored per shape. Replaces the 5 legacy per-shape wrapper nodes.

ParameterDefaultDescription
shapecircleDropdown: circle, rectangle, ellipse, polygon, line, triangle, star, diamond, cross, rounded_rectangle, heart, arrow
cx / cy256Center position (center-based shapes)
radius50Circle radius, triangle/heart size
size_w / size_h200 / 100Rectangle, rounded rect, diamond, arrow width/height
rx / ry100 / 50Ellipse radii
top_left_x / top_left_y100Rectangle/line start position
x2 / y2400Line end position
thickness5Line, cross thickness
outer_r / inner_r100 / 40Star radii
num_points5Star/polygon point count
corner_radius20Rounded rectangle corners
arrow_length / head_length / head_widthArrow dimensions
points_jsonPolygon vertices: [[x1,y1], ...]
value1.0Fill intensity
feather0.0Edge softness
rotation0.0Rotation in degrees
operationsetset / add / subtract / max / min
batch_size1Number of mask frames

Optional: coords_json (per-frame position override), existing_mask, reference_image

Output: mask (MASK)


Mask Composite Advanced (MEC)

Combine two masks with compositing operations.

OperationDescription
unionCombine both (max)
intersectOverlap only (min)
subtractA minus B
xorExclusive — one or the other, not both
blendWeighted average
min / maxPer-pixel min / max
differenceAbsolute difference

Automatically resizes masks to match if spatial dimensions differ.


Mask Math (MEC)

Mathematical operations on a single mask.

OperationDescription
add_scalarAdd constant value
multiply_scalarMultiply by value
powerRaise to power
invert1 − mask
clampClamp to [value_a, value_b] range
remap_rangeRemap from [value_a, value_b][0, 1]
quantizeSnap to N discrete levels
threshold_hysteresisDual-threshold with connected regions
gammaGamma correction
contrastContrast adjustment
abs_diff_from_valueAbsolute difference from value

All outputs are clamped to [0, 1].


Inpainting

Inpaint Crop Pro (MEC)

Crop image tightly around the mask region for focused inpainting, with separate inpaint and stitch blend masks. Feed the crop to any inpaint model, then stitch back seamlessly.

How it works: Computes tight bounding box around the mask, expands by context_expand, produces two separate masks — one for the inpaint model (crisp or feathered) and one for compositing back (Gaussian, edge-aware, Laplacian pyramid, or FFT frequency blend). Supports video-stable cropping (union bbox across all frames).

ParameterDefaultDescription
imageInput image batch
maskInpaint mask (white = area to inpaint)
context_expand1.5Crop expansion factor beyond mask bounds (1.0 = tight)
inpaint_mask_modehard_binaryWhat the model sees: hard_binary / slight_feather / soft_blend
stitch_blend_modegaussianCompositing mode: edge_aware / gaussian / laplacian_pyramid / frequency_blend
blend_radius32Feather radius for stitch blend mask
size_modefree_sizefree_size / forced_size (exact W×H) / ranged_size (min/max clamp)
forced_width / forced_height1024Target dimensions for forced_size mode
min_size / max_size512 / 2048Dimension clamp for ranged_size mode
padding_multiple8Pad output to be divisible by N
video_stable_cropfalseLock bbox across all frames for video consistency
fill_masked_areaedge_padFill masked area in crop: edge_pad / neutral_gray / original
downscale_methodlanczosInterpolation for downscaling: lanczos / bicubic / bilinear / nearest-exact / area
upscale_methodlanczosInterpolation for upscaling: same options

Outputs: stitch_data, cropped_image, inpaint_mask, stitch_blend_mask, crop_mask, cropped_composite, info

cropped_composite is a red-tinted debug preview showing the mask overlay on the crop — useful for verifying region coverage.

Who is it for? Inpainting power users who want crop → inpaint → stitch with professional blend modes (Laplacian pyramid, frequency blend, edge-aware).


Inpaint Composite (MEC) — unified Stitch + Paste Back

Single node that combines Inpaint Stitch Pro and Inpaint Paste Back behind one mode dropdown. The frontend hides parameters that don't apply to the current mode so the UI stays clean.

ParameterDefaultUsed in modeDescription
stitch_databothFrom Inpaint Crop Pro
inpainted_imagebothInpainted result from any model
modestitch_probothstitch_pro (advanced blend pipeline) or paste_back (clean resize + paste)
blend_mode_overridefrom_cropstitch_proOverride blend mode or keep what the crop node configured
color_matchfalsestitch_proReinhard mean+std color transfer before blending
upscale_methodlanczospaste_backResize interpolation for the inpainted crop
feather_edgesfalsepaste_backGaussian-feather the paste-rect boundary
feather_radius16paste_backFeather radius in pixels (0 disables)

Outputs: image, mask, info

  • In stitch_pro mode mask is the actual blend mask used (Laplacian / edge-aware / FFT etc).
  • In paste_back mode mask is the paste rectangle (feathered if enabled), so downstream nodes always get a usable mask.

When to use which mode

ModeUse when…
stitch_proYou want pro-level seam-hiding (Laplacian pyramid, edge-aware, FFT frequency blend). Slightly heavier.
paste_backYou just want a clean resize + paste (optionally feathered). Faster, deterministic, no blend pipeline.

Backward compatibility: the legacy Inpaint Stitch Pro (MEC) and Inpaint Paste Back (MEC) nodes are still registered (now labelled "legacy") so existing workflows keep working. New workflows should use Inpaint Composite (MEC).


Inpaint Stitch Pro (MEC) — legacy, prefer Inpaint Composite

Composite inpainted image back into the original using stitch data from Inpaint Crop Pro.

How it works: Takes the inpainted result and the stitch data, resizes and places it back at the original crop location, blending using the stored blend mask. Optional mean+std color matching reduces color shift at boundaries.

ParameterDefaultDescription
stitch_dataFrom Inpaint Crop Pro
inpainted_imageInpainted result from any model
blend_mode_overridefrom_cropOverride blend mode or keep original
color_matchfalseApply mean+std color transfer before stitching

Outputs: image, blend_mask_used, info


Inpaint Mask Prepare (MEC)

Standalone mask cleanup and dual-mask preparation for inpainting workflows.

How it works: Fills holes, removes small disconnected blobs, dilates the mask, then produces two outputs — a clean inpaint mask (for the model) and a stitch blend mask (for compositing). Optional temporal smoothing for video batch consistency.

ParameterDefaultDescription
maskRaw input mask
fill_holestrueFill interior holes
remove_small_regionstrueRemove disconnected blobs
min_region_area100Minimum region area in pixels
grow_pixels4Dilate mask by N pixels
inpaint_edge_modehard_binaryhard_binary / slight_feather
stitch_edge_modegaussiangaussian / edge_aware
stitch_feather_radius16Feather radius for stitch blend
temporal_smoothfalseGaussian smoothing along batch dimension
temporal_sigma1.5Temporal smoothing sigma (frames)
reference_image(optional)For edge-aware stitch blend

Outputs: inpaint_mask, stitch_blend_mask, debug_preview, info


Inpaint Paste Back (MEC) — legacy, prefer Inpaint Composite

Simple paste-back node: resize the inpainted crop and composite it onto the original with optional Gaussian-feathered alpha blending.

ParameterDefaultDescription
stitch_dataFrom Inpaint Crop Pro
inpainted_imageInpainted result from any model
feather_edgestrueGaussian-feathered alpha blending at crop boundary
feather_radius8Blur radius for edge feathering (pixels)

Outputs: image, info

Paste Back vs Stitch Pro vs Composite: All three live in the same suite. The new Inpaint Composite (MEC) node merges Stitch Pro and Paste Back behind one mode dropdown — prefer it for new workflows. The two legacy nodes remain for backward compatibility.


Image Comparer (MEC)

Interactive before/after comparison widget with 3 modes: drag-slider split, overlay blend, and difference heatmap.

ParameterDefaultDescription
image_aLeft / "before" image
image_bRight / "after" image
label_a"Before"(optional) Label for image A
label_b"After"(optional) Label for image B

Modes: ◧ Compare (drag slider) · ⊕ Overlay (alpha blend) · ≠ Diff (heatmap)

Who is it for? Quick visual comparison of before/after results — inpainting QA, model comparison, parameter tuning.


Batch & Video

Mask Batch Manager (MEC)

Manipulate mask batches for video workflows.

OperationDescription
sliceExtract frame range [start:end]
pick_framesSelect specific frames by index
repeatRepeat mask N times
reverseReverse frame order
concatJoin two mask batches
interleaveAlternate frames from two batches
insertInsert mask_b at position
removeRemove frame at index

Mask Propagate Video (MEC)

Draw mask on frame 1 → propagate across all frames.

ModeDescription
staticSame mask on every frame
fadeLinear fade to zero
scale_linearLinear scale over time
optical_flowTrack mask using optical flow
sam2_videoUse SAM2 video predictor for tracking

Temporal Anchor System (MEC)

Mask interpolation over time using Signed Distance Fields (SDF). Define masks on a few key frames and let the node smoothly morph between them across the full video.

How it works: Computes an SDF for each anchor mask (distance from boundary, negative inside, positive outside), then interpolates the SDF fields between anchor frames using configurable easing. The zero-crossing of the blended SDF produces the interpolated mask boundary. Optional optical flow refinement (Farneback or FFT phase correlation) warps the SDF to follow motion.

ParameterDefaultDescription
anchor_masksOne mask per anchor frame (A, H, W)
anchor_frames"0"Comma-separated frame indices (e.g. "0,10,30")
total_frames30Total output frames
easingsmooth_steplinear / ease_in / ease_out / smooth_step
sdf_iterations64SDF diffusion iterations (more = more accurate)
flow_refinementfalseEnable optical flow refinement
images(optional)Video frames for optical flow estimation

Outputs: full_masks (total_frames × H × W), confidence (per-frame float list), info

Who is it for? Video editors who need smooth mask morphing between keyframes — rotoscoping helpers, animated mask transitions, temporal mask interpolation where SAM tracking is overkill.


Video Frame Extractor (MEC)

Extract a single frame from a video batch.

ParameterDefaultDescription
modefirstfirst / last / middle / specific_frame
frame_index0Frame index for specific_frame mode (clamped to batch size)

Outputs: frame (IMAGE), total_frames (INT), is_video (BOOLEAN)


BBox Tools

Six nodes for bounding box manipulation:

NodeDescription
BBox CreateManual [x, y, width, height] entry
BBox From MaskExtract tight bbox from non-zero mask pixels with per-axis padding
BBox To MaskConvert bbox to a rectangular mask
BBox PadAsymmetric padding (top/bottom/left/right) with canvas clamping
BBox CropCrop image + mask to bbox region
BBox Smooth TemporalSmooth bbox sequences across video frames (moving-average / exponential)

All BBox nodes clamp outputs to valid canvas bounds — no negative dimensions, no out-of-bounds errors.


Diagnostics

Mask Failure Explainer (MEC)

Diagnose why a mask failed and get actionable fix suggestions. Pure tensor analysis — no models, no VRAM.

How it works: Runs a 5-metric analysis pipeline on your image + mask pair:

MetricWhat it measuresFailure threshold
BrightnessBT.709 mean luminanceDark scene < 0.15
BlurLaplacian variance × 1000Blurry image < 50
Boundary contrastStd deviation at mask edge ringLow contrast < 0.05
Color confusionMean color distance inside vs. outside maskHigh confusion < 0.1
Background complexitySobel edge density outside maskBusy background > 0.3

Each metric contributes up to 20 points to a severity score (0–100). The node outputs a human-readable explanation, a problem-regions heatmap, the severity score, and a suggested method (e.g. "try ViTMatte for complex edges" or "use BiRefNet for busy backgrounds").

ParameterDefaultDescription
imageInput image(s)
maskMask to diagnose
ring_width5Boundary ring width for contrast analysis
blur_threshold50.0Laplacian variance threshold
brightness_threshold0.15Dark scene threshold

Outputs: explanation (text), problem_regions_mask (heatmap), severity_score (0–100), suggested_method (string)

Who is it for? Anyone whose mask looks wrong and doesn't know why. Plug in your image + bad mask, read the diagnosis, follow the suggestion. Especially useful for beginners learning which segmentation method works for which scenario.


Interactive Editor

Points Mask Editor (MEC)

Full-featured interactive canvas editor for placing points and bounding boxes directly on your image.

ActionEffect
Left clickAdd positive point (foreground)
Right clickAdd negative point (background)
CTRL + Left dragDraw positive bounding box (green)
CTRL + Right dragDraw negative bounding box (red)
Shift + ClickDelete element under cursor
Scroll wheelAdjust point radius
CTRL + ScrollZoom in/out
Middle mouse dragPan canvas
Delete / BackspaceDelete hovered element
CTRL + Z / CTRL + Shift + ZUndo / Redo
RReset view

Toolbar: Pill counters for +pts / −pts / bbox count / radius. Buttons for ✕ Pts, ✕ BBox, ✕ All, ↶ Undo / Redo ↷, ▣ Fit.

Outputs (8):

OutputTypeDescription
maskMASKRendered points/bboxes mask
positive_coordsSTRING[{"x":int,"y":int}, ...] for SAM
negative_coordsSTRING[{"x":int,"y":int}, ...] for SAM
bboxesBBOXPositive bounding boxes
neg_bboxesBBOXNegative bounding boxes (SAM3)
points_jsonSTRINGFull point data for SAM Mask Generator
bbox_jsonSTRINGPrimary bbox for SAM Mask Generator
primary_bboxBBOX[x,y,w,h] for BBox pipeline

Connect a reference_image to see it as the editor background for precise placement.


Spline Mask Editor (MEC) ★ New

Interactive canvas for drawing spline-based masks directly on your image. Supports Catmull-Rom (smooth curves through points), Bezier (with tangent handles), and polyline (straight segments) modes.

ActionEffect
Left clickAdd control point (or close path by clicking first point)
Shift + clickDelete point under cursor
Ctrl + clickInsert point on nearest curve segment
Right-clickContext menu (Delete Point, Open/Close, Smooth/Sharp)
S keyToggle smooth / sharp interpolation for current path
Scroll wheelZoom in/out
Middle mouse dragPan canvas

Key improvements: Normalized [0,1] coordinates (resolution-independent), zoom-relative point sizes, segment insertion, close-by-clicking-first-point affordance (highlighted orange), property-based persistence.

ParameterDefaultDescription
spline_typecatmull_romcatmull_rom / bezier / polyline
closedtrueClose the spline loop for filled region
smoothingtrueEnable spline smoothing
samples_per_segment20Curve resolution (higher = smoother)
feather_radius0.0Gaussian edge softness
invertfalseFill outside spline instead of inside

Outputs: mask (MASK), coords_json (SAM-compatible points), spline_data_out (for Motion Mask Tracker)


Motion Mask Tracker (MEC) ★ New

Per-frame motion detection with 4 independent methods and camera stabilization. Feed a video batch — get a motion mask highlighting what moved between frames.

MethodDescription
pixel_diffAbsolute per-pixel brightness change
optical_flowFarneback dense flow or phase correlation
background_subStatic background model from first N frames
histogram_diffPer-region color histogram distance
ParameterDefaultDescription
camera_compensationtrueSubtract global camera motion (homography/affine/translation)
detection_modecombinedcombined / individual method
combine_methodunionunion (any triggers) / intersection (all agree)
grow_pixels4.0Expand detected regions
min_region_size100Remove noise regions < N pixels
temporal_smoothtrueGaussian smoothing across frames

Outputs: motion_mask (MASK), motion_intensity (FLOAT), info (STRING)

Who is it for? Video editors who need automatic motion masks for selective effects, stabilization-aware change detection, or motion-triggered workflows.


Preview

Video Frame Player (MEC)

In-graph video scrubber with drag-crop overlay, trim range, frame stride, lanczos resize, and upscale — all in one node so you don't have to chain Load → Trim → Crop → Resize → Preview. Plays inside the node, supports play/pause + ping-pong loop + I/O hotkeys (mark IN/OUT), and emits the trimmed/cropped/resized batch ready to feed a sampler.

GroupHighlights
Sourceframes, frame_index, output_mode (current_frame / all_frames)
Trim & playbackframe_start/frame_end (drag green/red markers on the timeline), frame_stride (orange ticks), playback_fps, loop_mode (once/loop/ping-pong)
Cropcrop_enabled, crop_locked, aspect_ratio (free / 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 2:1 / 21:9 / original / custom), crop_x/y/w/h set by drag overlay (8 handles + interior move, dim outside, rule-of-thirds guides, live W×H readout)
Resizeresize_method (none / lanczos / bicubic / bilinear / area / nearest-exact), target_width, target_height, upscale_factor
Outputsframe, frame_index, frame_count, processed, out_width, out_height, crop_x_px, crop_y_px, crop_w_px, crop_h_px, trimmed_count, playback_fps

Hotkeys (canvas focused): Space play/pause, ←/→ step ±1 (Shift = ±10), Home/End jump to trim bounds, I/O mark IN/OUT at current frame, R reset crop to full frame.

Full parameter table, pipeline order, and recipes (TikTok 9:16, half-rate stride, 2× lanczos upscale, hero-frame img2img): see docs/video-frame-player.md.


Mask Preview Overlay (MEC)

Visualize masks with 5 display modes:

ModeDescription
overlayRed-tinted mask overlaid on the image
binary_maskBlack & white mask only
edge_onlyShow mask edges / contours
side_by_sideOriginal image next to masked version
alpha_channelRGBA with alpha from mask

Handles batch size mismatches automatically (expands or repeats to match).


Utilities

Universal Reroute / Dot (MEC)

Nuke-style reroute dot that accepts any connection type (IMAGE, MASK, LATENT, STRING, INT, FLOAT, etc.). Use it to keep your workflow wires clean and organized.

Parameter History (MEC)

Tracks every parameter change across ComfyUI runs in a local SQLite database. Query with:

ModeDescription
all_historyFull parameter history for last N runs
last_run_diffWhat changed between the last two runs
node_class_filterFilter history by node class name

FolderIncrementer

Filesystem-aware auto-versioning for output files.

NodeDescription
Folder Version IncrementerScans output directory for v001, v002, … and returns the next available version
Folder Version CheckReports how many versions exist
Folder Version SetReserves version slots by creating placeholder directories

Key features:

  • Filesystem-based — no global counter file; scans the actual directory
  • Cancel-safe — if you cancel mid-execution, no version is wasted
  • Extension-preservingphoto.pngphoto/v001/photo.png
  • Optional suffix — set the new suffix widget (e.g. _Inpaint) and the basename of filename_prefix / output_filename becomes photo_Inpaint (folder + version_string are unchanged). No more downstream Concatenate nodes just to tag a pass.

Outputs:

OutputExamplePurpose
version_stringv001Version tag
version_number1Integer version
folder_namephotoDerived from source filename
subfolder_pathphoto/v001For Save Image subfolder
filename_prefixphoto/v001/photoWithout extension
output_filenamephoto/v001/photo.pngFull output path

Node Quick-Reference Table

All 47 nodes at a glance:

#NodeCategoryVRAM TierWhat it does
1SAM Model LoaderSAM2Load SAM 2.1 / SAM 3 checkpoints
2SAM Mask GeneratorSAM2SAM inference with point + bbox prompts
3SAM Multi-Mask PickerSAM2View all 3 SAM candidates, pick interactively
4Unified SegmentationSAM2One-node dispatcher for all segmentation backends
5SAM + ViTMatte PipelineSAM / Matting2SAM → refinement → ViTMatte end-to-end
6SeC + MatAnyone2 PipelineSAM / Matting3SeC → MatAnyone2 temporal video pipeline
7Semantic SegmentSegmentation2SegFormer face/body/clothes parsing
8Background RemoverMatting2One-click RMBG / BiRefNet removal
9Matting NodeMatting2Unified 7-backend alpha matting
10ViTMatte Edge RefinerMatting2Standalone edge refinement (7 methods)
11Trimap GeneratorMatting1Generate trimap for ViTMatte input
12Luminance KeyerKeying1BT.709 luminance keying with smoothstep
13Mask Transform XYEditing1Per-axis erode/expand/blur/offset
14Mask Draw FrameEditing1Draw 12 shapes with rotation and SDF
15Draw ShapeEditing1Unified 12-shape dropdown with all params — replaces per-shape wrappers
16Mask Composite AdvancedEditing1Boolean/blend two masks (8 operations)
17Mask MathEditing1Mathematical mask operations (11 ops)
18Spline Mask EditorInteractive1Interactive Catmull-Rom / Bezier / polyline spline drawing on canvas
19Inpaint Crop ProInpaint1Crop around mask for inpainting
20Inpaint CompositeInpaint1Unified Stitch Pro + Paste Back (mode dropdown)
20aInpaint Stitch Pro (legacy)Inpaint1Composite inpainted result back
21Inpaint Paste Back (legacy)Inpaint1Simple paste-back with feathered alpha
22Inpaint Mask PrepareInpaint1Clean + dual-mask preparation
23Image ComparerPreview1Interactive before/after comparison (3 modes)
24Mask Batch ManagerVideo1Slice/concat/interleave mask batches
25Mask Propagate VideoVideo1–2Propagate mask across video frames
26Temporal Anchor SystemVideo2SDF-based mask interpolation between keyframes
27Motion Mask TrackerVideo1Per-frame motion detection (4 methods, camera stabilization)
28Video Frame ExtractorVideo1Extract single frame from batch
29BBox CreateBBox1Manual bbox entry
30BBox From MaskBBox1Extract bbox from mask
31BBox To MaskBBox1Convert bbox to mask
32BBox PadBBox1Asymmetric bbox padding
33BBox CropBBox1Crop image + mask to bbox
34BBox Smooth TemporalBBox1Smooth bbox sequences across video frames
35Mask Failure ExplainerDiagnostics1Diagnose bad masks, suggest fixes
36Points Mask EditorInteractive1Canvas editor for points/bboxes
37Mask Preview OverlayPreview15-mode mask visualization
38Universal Reroute / DotUtility1Any-type wire reroute
39Parameter HistoryUtility1Track parameter changes over runs
40Folder Version IncrementerOutput1Auto-versioned file output
41Folder Version CheckOutput1Check existing versions
42Folder Version SetOutput1Reserve version slots
43–47Draw Circle / Rectangle / Ellipse / Polygon / LineEditing1(Deprecated) Legacy per-shape wrappers — use Draw Shape instead
48VAE MergeVAE1Merge 2/3 VAEs (8 algorithms, per-block alpha)
49VAE Latent InspectorVAE1Per-channel stats, NaN/Inf checks, health verdict
50VAE Similarity AnalyserVAE1Cosine similarity (global + per-block) between two VAEs
51VAE Block InspectorVAE1Per-block weight stats for a single VAE
52Color Space ConvertColor1sRGB ↔ linear ↔ Rec.709 ↔ ACEScg
53LUT Apply (.cube)Color1Adobe .cube 1D/3D LUT with strength blend
54Exposure GradeColor1Stops + WB temp/tint + contrast pivot
55Load EXRI/O1OpenEXR → imageio → TIFF fallback
56Save EXRI/O1Half-float by default, TIFF fallback
57EXR Metadata ReaderI/O1Pure-python header parser (no OpenEXR needed)
58Merge Render PassesRender1Beauty + diffuse/spec/emission/AO compositing
59Depth-of-Field MaskRender1Depth pass → CoC alpha mask
60Depth WarpGeometry1Horizontal parallax warp from depth
61Normal → CurvatureGeometry1Curvature mask from a tangent-space normal pass
62Position Pass SplitterGeometry1Split position pass into X/Y/Z masks
63Grain MatchPlate1Extract grain from reference plate, re-apply to target
64Plate StabilizerPlate1ORB+RANSAC affine (cv2) → FFT translation fallback
65Clean Plate ExtractorPlate1Median across batch with optional mask exclusion
66Difference MattePlate1L1/L2 image diff → MASK with threshold + softness
67Metadata WriterMetadata1Write/merge JSON sidecars next to outputs
68Frame Range RouterMetadata1Slice IMAGE/MASK batches [start:end:step]
69Shot Metadata ReaderMetadata1Read shot.json (show / shot / task / frame in/out / fps)
70Batch Version ManagerOutput1<root>/<show>/<shot>/<task>/v###/ with atomic reservation
71Temporal Consistency CheckerDiagnostics1Flicker score (mask_iou / pixel_diff / Farneback flow)
72Model Metadata ExtractorDiagnostics1Inspect safetensors/checkpoints without unpickling

VRAM Tiers: 1 = pure tensor math (CPU/GPU, no models), 2 = loads a model (~1–4 GB), 3 = loads multiple models


Workflows

Best Quality Masking (Single Image)

[SAM Model Loader]          [Load Image]
  offload_to_cpu: true         ↓
  dtype: float16          [Points Mask Editor]
        ↓                    ↓ points_json, bbox_json
[SAM + ViTMatte Pipeline] ←─┘
  sam_iterations: 2–3
  refine_method: auto
  detail_preservation: 0.85
  edge_contrast: 1.2
        ↓
  refined_mask → compositing

Fast Iteration

[SAM Mask Generator]  →  [ViTMatte Edge Refiner]
  refine_iterations: 2       method: multi_scale_guided

Pick the Best SAM Mask

[Load Image]  →  [Points Mask Editor]  →  [SAM Multi-Mask Picker]
                                              ↓ click thumbnail
                                         selected_mask → downstream

Inpaint Pipeline

[Load Image] + [Mask]  →  [Inpaint Crop Pro]     →  [Any Inpaint Model]
                              context_expand: 1.5        ↓
                              stitch_blend: edge_aware   [Inpaint Stitch Pro]
                                    ↓ stitch_data ──────→     ↓
                                                         seamless result

Video Masking

[Load Video]  →  [Video Frame Extractor]  →  [Points Mask Editor]
                   mode: first                      ↓
                                            [SAM Mask Generator]
                                                    ↓
                                            [Mask Propagate Video]
                                              mode: sam2_video
                                                    ↓
                                              per-frame masks

Temporal Mask Morphing

[Define masks on frames 0, 15, 30]  →  [Temporal Anchor System]
                                          anchor_frames: "0,15,30"
                                          total_frames: 60
                                          easing: smooth_step
                                                ↓
                                          60 interpolated masks

Alpha Matting (From Any Coarse Mask)

[Any Segmentation Node]  →  [Matting Node]
                               backend: auto
                               edge_radius: 15
                                    ↓
                              alpha_mask → compositing

Diagnose a Bad Mask

[Load Image] + [Bad Mask]  →  [Mask Failure Explainer]
                                    ↓
                              explanation: "Dark scene (mean=0.12), low boundary contrast"
                              suggested_method: "Try ViTMatte with edge_radius=20"
                              severity: 65/100

Luminance Keying

[Load Image]  →  [Luminance Keyer]
                    mode: auto
                    falloff: 1.0
                    gamma: 1.0
                       ↓
                  luminance mask (highlights / shadows / midtones)

SeC + MEC (Video Object Segmentation)

SeC handles tracking, MEC handles edge quality:

[SeC Video Segmentation]  →  [ViTMatte Edge Refiner (MEC)]  →  refined masks

Install SeC: cd ComfyUI/custom_nodes && git clone https://github.com/9nate-drake/Comfyui-SecNodes

Spline Mask Drawing

[Load Image]  →  [Spline Mask Editor]
                    spline_type: catmull_rom
                    closed: true
                    feather_radius: 2.0
                       ↓
                  mask → any mask input
                  coords_json → SAM Mask Generator
                  spline_data → Motion Mask Tracker

Motion Detection (Video)

[Load Video Frames]  →  [Motion Mask Tracker]
                           camera_compensation: true
                           detection_mode: combined
                           grow_pixels: 4
                                ↓
                          motion_mask → compositing / routing
                          motion_intensity → Switch node

Draw Shape (Quick Masking)

[Draw Shape (MEC)]
   shape: star
   cx: 256, cy: 256
   outer_r: 100, inner_r: 40
   num_points: 5
   feather: 4.0
        ↓
   mask → downstream

VRAM Management

All nodes are designed to work on low-end GPUs (4–6 GB VRAM):

  • VRAM monitoring — model loading logs a warning when free VRAM drops below 2 GB
  • OOM recovery — if GPU runs out of memory, nodes fall back to CPU instead of crashing
  • Offload to CPU — SAM Model Loader has offload_to_cpu to keep models in system RAM
  • Auto memory cleanup — all nodes run gc.collect() + torch.cuda.empty_cache() in finally blocks
  • dtype control — use float16 or bfloat16 to halve VRAM usage
  • Torch-only fallbacks — if opencv-python is not installed, all nodes fall back to pure PyTorch implementations (slightly slower but functional)
  • VRAM tiers — each node declares its tier (1 = no model, 2 = one model, 3 = multiple models) so you can plan your workflow

Running Tests

The test suite covers all pure-tensor nodes (no GPU models required):

# Run all tests:
python -m pytest tests/ -v --tb=short

# Run a specific node's tests:
python -m pytest tests/test_luminance_keyer.py -v
python -m pytest tests/test_inpaint_suite.py -v
python -m pytest tests/test_mask_failure_explainer.py -v
python -m pytest tests/test_temporal_anchor.py -v
python -m pytest tests/test_sam_multi_mask_picker.py -v

Troubleshooting

ProblemSolution
ModuleNotFoundError: cv2pip install opencv-python>=4.7.0 — nodes will use torch fallbacks but cv2 gives better quality
ModuleNotFoundError: transformerspip install transformers pillow — only needed for ViTMatte matting
Torch version mismatch after pip install -r requirements.txtReinstall your ComfyUI torch: check PyTorch install page for your CUDA version
SAM model not foundPlace .pth / .pt / .safetensors in ComfyUI/models/sams/ or ComfyUI/models/sam2/
CUDA out of memoryEnable offload_to_cpu in SAM Model Loader, use float16 dtype, reduce image resolution
Nodes not showing in menuCheck console for [MEC] Loaded 44 message. If missing, check for import errors in the console output
ViTMatte download failsDownload manually from HuggingFace → place in ComfyUI/models/vitmatte/
My mask looks badConnect your image + mask to Mask Failure Explainer — it will diagnose the issue and suggest the right method

Project Structure

ComfyUI-CustomNodePacks/
├── __init__.py                     # Node registration (47 nodes)
├── folder_incrementer.py           # FolderIncrementer nodes (3)
├── conftest.py                     # Pytest root configuration
├── pyproject.toml                  # Package metadata
├── requirements.txt                # Dependencies
├── js/
│   ├── folder_incrementer.js       # Frontend: FolderIncrementer
│   ├── image_comparer.js           # Frontend: before/after comparison widget
│   ├── points_bbox_editor.js       # Frontend: interactive canvas editor
│   ├── parameter_memory.js         # Frontend: parameter history UI
│   ├── sam_multi_mask_picker.js    # Frontend: 3-mask thumbnail picker
│   ├── spline_mask_editor.js       # Frontend: spline drawing canvas (normalized coords)
│   └── universal_reroute.js        # Frontend: Nuke-style dot
├── nodes/
│   ├── sam_model_loader.py         # SAM 2.1 / SAM 3 model loader
│   ├── sam_mask_generator.py       # SAM inference engine
│   ├── sam_multi_mask_picker.py    # Multi-mask picker + JS widget
│   ├── sam_vitmatte_pipeline.py    # SAM → ViTMatte end-to-end pipeline
│   ├── sec_matanyone_pipeline.py   # SeC → MatAnyone2 video pipeline
│   ├── unified_segmentation_node.py# Unified segmentation dispatcher
│   ├── unified_segmentation.py     # Segmentation backends (deprecated)
│   ├── semantic_segment.py         # SegFormer face/clothes parsing
│   ├── background_remover.py       # RMBG / BiRefNet background removal
│   ├── matting_node.py             # 7-backend alpha matting
│   ├── vitmatte_refiner.py         # Standalone edge refiner
│   ├── trimap_generator.py         # Trimap generation
│   ├── luminance_keyer.py          # BT.709 luminance keyer
│   ├── mask_transform_xy.py        # Per-axis mask transform
│   ├── mask_draw_frame.py          # Shape drawing (12 shapes + DrawShapeMEC unified node)
│   ├── mask_composite.py           # Mask compositing ops
│   ├── mask_math.py                # Mathematical mask ops
│   ├── mask_batch_manager.py       # Batch manipulation
│   ├── mask_propagate_video.py     # Video mask propagation
│   ├── mask_preview.py             # Mask visualization
│   ├── mask_failure_explainer.py   # Mask diagnostics engine
│   ├── temporal_anchor.py          # SDF interpolation system
│   ├── inpaint_suite.py            # Crop/stitch/paste-back/prepare (4 nodes)
│   ├── bbox_nodes.py               # BBox tools (6 nodes incl. BBoxSmooth)
│   ├── points_mask_editor.py       # Interactive point/bbox editor
│   ├── spline_mask_editor.py       # Interactive spline mask drawing
│   ├── motion_mask_tracker.py      # Per-frame motion detection (4 methods)
│   ├── stabilization_utils.py      # Camera stabilization helpers
│   ├── video_frame_extractor.py    # Frame extraction
│   ├── image_comparer.py           # Before/after image comparison
│   ├── universal_reroute.py        # Nuke-style reroute dot
│   ├── parameter_memory.py         # Parameter history + SQLite
│   ├── model_manager.py            # Shared model cache & download
│   └── utils.py                    # Shared utilities
├── docs/
│   ├── inpaint-suite.md            # Inpaint Crop/Stitch/Paste Back/Prepare
│   ├── mask-editing.md             # Transform, Draw, Composite, Math, Batch, Preview
│   ├── sam-segmentation.md         # SAM, Unified Segmentation, Pipelines
│   ├── matting-refinement.md       # Matting, ViTMatte, Trimap, Keyer
│   ├── video-temporal-bbox.md      # Video, Temporal Anchor, BBox tools
│   └── utility-nodes.md            # Editor, Comparer, Diagnostics, Utils
├── tests/
│   ├── test_luminance_keyer.py     # 38 tests
│   ├── test_inpaint_suite.py       # Inpaint suite tests
│   ├── test_mask_failure_explainer.py # Diagnostics tests
│   ├── test_temporal_anchor.py     # Temporal anchor tests
│   └── test_sam_multi_mask_picker.py  # Multi-mask picker tests
├── example_workflows/
│   ├── basic_sam_segmentation.json
│   ├── sam_vitmatte_pipeline.json
│   ├── mask_editing_toolkit.json
│   ├── bbox_pipeline.json
│   └── video_mask_propagation.json
└── third_party/                    # Reference implementations

Acknowledgements

This project builds on or references the following open-source work:

ProjectAuthorLicenseDescription
Segment AnythingMeta AIApache-2.0SAM foundation model
Segment Anything 2Meta AIApache-2.0SAM2 / SAM2.1 video segmentation
SAM-HQSysCV (ETH Zurich)Apache-2.0High-quality SAM variant (NeurIPS 2023)
ViTMatteHUST VLMITVision Transformer alpha matting
Matte-AnythingHUST VLMITInteractive SAM + matting pipeline
MatAnyone2NTU S-LabS-Lab-1.0Video matting with learned quality evaluator
RobustVideoMattingPeterL1n / ByteDanceGPL-3.0Real-time human video matting
CutiehkchengrexMITVideo object segmentation (CVPR 2024)
ComfyUI-segment-anything-2kijaiApache-2.0SAM2 ComfyUI nodes with points editor
ComfyUI-SecNodes9nate-drakeApache-2.0SeC 4B video segmentation nodes
ComfyUI-MatAnyoneFuouMMITMatAnyone ComfyUI wrapper
ComfyUI-RMBG1038labGPL-3.0RMBG-2.0 / BiRefNet background removal
ComfyUI-KJNodeskijaiGPL-3.0Utility node collection
ComfyUI-Inpaint-CropAndStitchlquesadaGPL-3.0Crop-and-stitch inpainting reference
ComfyUI-VideoMaMaokdaltoVideoMaMa mask-guided video matting
ComfyUI LayerStylechflame163MITLayer compositing node suite
ComfyUI LayerStyle Advancechflame163MITAdvanced nodes (BiRefNet, Florence2, etc.)

License

MIT


Use in image/video generation pipelines (Flux / Qwen-Image / Wan / Z-Image / ERNIE-VL)

This umbrella pack aggregates ~72 nodes across four sub-namespaces — Folder Incrementer (_FOLDER_MAPPINGS, 3 nodes), MEC tools (_MEC_MAPPINGS, 30 nodes covering masking, SAM/ViT-Matte segmentation, inpaint crop/stitch/paste-back, spline editors, motion mask trackers, draw shapes, VAE merge/inspect, batch version manager, temporal consistency, model metadata, image comparer, parameter history, semantic segment, luminance keyer, mask failure explainer, temporal anchor, SAM multi-mask picker), Paint nodes (_PAINT_MAPPINGS), and MA nodes (_MA_MAPPINGS). The nodes are model-agnostic — they speak ComfyUI's native IMAGE, MASK, LATENT, VAE, and MODEL types — so they slot into any sampler graph regardless of which diffusion family produces the pixels.

Model familyRecommended bridges
FluxUse InpaintCropProMEC + InpaintStitchProMEC + InpaintPasteBackMEC to confine high-resolution Flux refinement to a tracked region. SAMViTMattePipelineMEC and TrimapGeneratorMEC produce the high-quality alpha that Flux-driven matte refinement needs. BatchVersionManagerMEC (combined with FolderIncrementer) keeps versioned outputs across sweeps. VAEMergeMEC / VAELatentInspectorMEC are useful when comparing Flux VAE variants.
Qwen-ImageIdentical inpaint and matte pattern as Flux. MaskTransformXY and MaskPropagateVideo are useful when reusing a single Qwen-Image generated mask across a small sequence. ImageComparerMEC for A/B sweeps over guidance / sampler choices.
Wan 2.x (video)MotionMaskTrackerMEC, MaskPropagateVideo, TemporalAnchorMEC, SeCMatAnyonePipelineMEC and TemporalConsistencyCheckerMEC are designed for the video domain — keep masks coherent across Wan-Animate frames, anchor a key-frame mask, and audit temporal jitter. MaskFailureExplainerMEC flags problem frames before re-rendering. Pair with ComfyUI-WanAnimatePreprocessV2 (human) or ComfyUI-WanAnimalPreprocess (animal) for the pose / face conditioning.
Z-ImageSame inpaint and refine bridges as Flux/Qwen. The spline-mask, draw-shape, and points-mask editors are useful when authoring a custom region for Z-Image's refinement passes.
GLM-ImageThe IMAGE outputs feed cleanly into the GLM-Image I2I path (via the sampler's optional image input + denoise_strength). BackgroundRemoverMEC + SAMMaskGeneratorMEC provide the alpha pre-stage.
ERNIE-VLNot applicable for sampling (ERNIE-VL is a multimodal LLM). The ModelMetadataExtractorMEC and ParameterHistoryMEC nodes can still be useful for cataloguing assets that ERNIE-VL has captioned.

Two general patterns recur across all sampler families:

  1. Inpaint trioInpaintCropProMEC → diffusion sampler (any family) → InpaintPasteBackMEC (or InpaintStitchProMEC for soft seams). Allows full-resolution refinement at a fraction of the VRAM, regardless of which model is loaded.
  2. Versioned saves — wire BatchVersionManagerMEC (or the standalone FolderIncrementer) version_string into the sampler's Save Image.filename_prefix so every queued prompt produces a clean, ordered file series.

The UniversalRerouteMEC-equivalent typed reroutes (and the SAM / ViT-Matte loaders) keep the graph readable as it scales from a single Flux T2I bench into a multi-model Wan + Qwen-refine + Flux-detail composite.


Made with ❤️ for the ComfyUI community


Full Node & Parameter Reference

A complete, auto-generated reference covering every node, return type and widget exposed by this pack lives in NODE_REFERENCE.md. It is regenerated whenever INPUT_TYPES change.

Contributors

Languages

Python

51.8%

JavaScript

48.2%