Nodes/ComfyUI-CustomNodePacks/Image Mask Editor (C2C)
ComfyUI Node

Image Mask Editor (C2C)

Paint a mask that actually reaches the node

By Code2Collapse·Created 9 months ago·Updated about 8 hours ago· 59
Image Mask Editor (C2C)
  • image
  • input_mask
  • mask
  • preview
  • info
  • positive_coords
  • negative_coords
  • bboxes
  • neg_bboxes
  • points_json
  • bbox_json
  • primary_bbox
  • spline_data_out
  • painted_image
◄editor_id►
◄frame_modeper_frame►
◄grow0►
◄feather0►
◄threshold0.00►
◄invertfalse►
◄combinereplace►
◄modepaint►
◄canvas_layermask►
◄canvas_width512►
◄canvas_height512►
◄canvas_brush_typepaint►
◄canvas_brush_color#000000►
◄canvas_brush_opacity1.00►
◄canvas_brush_hardness0.80►
◄canvas_brush_size20►
◄canvas_mask_hardness0.50►
◄canvas_mask_expansion0►
◄canvas_mask_blur_radius0.0►
◄canvas_mask_blur_strength1.00►
◄canvas_data►
◄points_width512►
◄points_height512►
◄points_editor_data{"points":[],"bboxes":[]}►
◄points_default_radius3.0►
◄points_softness1.0►
◄points_normalizetrue►
◄shape_inputparameters►
◄shape_width512►
◄shape_height512►
◄shape_kindcircle►
◄shape_cx256.0►
◄shape_cy256.0►
◄shape_radius50.0►
◄shape_size_w200.0►
◄shape_size_h100.0►
◄shape_rx100.0►
◄shape_ry50.0►
◄shape_top_left_x100.0►
◄shape_top_left_y100.0►
◄shape_x2400.0►
◄shape_y2400.0►
◄shape_thickness5.0►
◄shape_outer_r100.0►
◄shape_inner_r40.0►
◄shape_num_points5►
◄shape_corner_radius20.0►
◄shape_cross_size100.0►
◄shape_arrow_length200.0►
◄shape_head_length60.0►
◄shape_head_width80.0►
◄shape_points_json[[100,100],[400,100],[400,400],[100,400]]►
◄shape_value1.00►
◄shape_rotation0.0►
◄shape_operationset►
◄shape_batch_size1►
◄shape_json{"cx": 256, "cy": 256, "radius": 50}►
◄shape_feather0.0►
◄spline_data[]►
◄spline_typecatmull_rom►
◄spline_closedtrue►
◄spline_samples_per_segment20►
◄spline_feather_radius0.0►
◄spline_invertfalse►
◄spline_smoothingtrue►
◄spline_centripetal_alpha0.50►
◄spline_width0►
◄spline_height0►
◄spline_mask_color#ff00ff►
◄spline_mask_opacity0.40►
◄spline_fillmask►
◄spline_flow_patternribbon►
◄spline_flow_thickness12.0►
◄spline_flow_amplitude8.0►
◄spline_flow_frequency2.0►
◄spline_flow_turbulence0.00►
◄spline_flow_turbulence_scale1.00►
◄spline_flow_edge_softness1.0►
◄spline_flow_taper_start0.00►
◄spline_flow_taper_end0.00►
◄spline_flow_frames1►
◄spline_flow_animation_speed0.050►
◄spline_flow_flow_directionforward►
◄spline_flow_mod_decay0.00►
◄spline_flow_seed0►
◄spline_flow_use_embedded_editortrue►
◄roto_json{"canvas": {"w": 1024, "h": 1024}, "frames": [{"frame": 0, "splines": []}]}►
◄roto_frame_count1►
◄roto_width1024►
◄roto_height1024►
◄roto_samples_per_seg24►
◄roto_feather_px0.0►
◄roto_frame0►
◄video_session_id►
◄video_tween_modedistance_transform►
◄video_feather0.0►
◄video_threshold0.00►
◄video_outside_keysempty►

ComfyUI's built-in mask editor is a right-click ritual: you open it on a LoadImage, paint something, save, and then discover the mask lives on that widget and is a pain to reuse, resize, or adjust. This is a full-window editor where the mask belongs to the node and - the part that matters - is a real MASK output you can wire anywhere.

You reach for it when a mask needs a human. Detectors are great until the subject holds an object in front of their face, and segmentation models are great until the edge is hair. Sometimes you just want to brush it in, at native resolution, over the exact image the node received.

How it works

The node keeps only an editor_id in the workflow. The painted masks are PNGs on the server under input/c2c_masks/<editor_id>/, so they survive a restart, and the workflow file stays small. The content hash of those masks is part of the cache key, which is the bit that makes it feel native: edit a mask and the graph re-runs, leave it alone and the graph stays cached.

What the editor shows depends on what you wire into image. A directly connected LoadImage or a C2C/VHS video loader shows its frames with no run needed. Anything computed - a crop, an upscale, a VAE decode - shows the exact frames the node received on its last run. Before that first run you get the nearest upstream preview with a banner telling you so, which is the honest way to handle it.

Tools are the set you'd expect and a couple you wouldn't: brush and eraser with size/hardness/opacity, rectangle, ellipse, polygon, lasso, bucket fill with tolerance, plus colour-range select and SAM smart-select if a SAM 2.1 model is available. Alt+stroke subtracts. View modes cycle overlay → matte → rubylith (the compositing convention: red tint over what's not selected) → outline → bare image. Batches get a frame strip with one mask per frame, and "Copy previous frame" is the shortcut that makes rotoscoping tolerable.

The parameters, and why this is the good design

grow, feather, threshold and invert are node parameters, not baked into the painting. Change a feather and nothing needs repainting. Note the sequencing the tooltip spells out: any non-zero grow hardens the edge first (every partly covered pixel counts), then feather softens it back. So grow +1 and feather 2 is a different mask from feather 2 alone.

frame_mode picks per_frame (each batch index uses its stored frame) or shared (frame 0 applies to everything). combine decides how the painted mask merges with an optional input_mask: replace, add, subtract, intersect - and without an input_mask connected, only replace does anything, since there's nothing to combine with.

Outputs: mask (the final [B,H,W] result, painted frames combined, then grown/feathered/thresholded/inverted), preview (your image with the mask tinted over it), and info (frame count, stored masks, mode, and any notes such as resized frames).

Install

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

Or "CustomNodePacks" in ComfyUI Manager, then restart ComfyUI. The editor is a JS frontend component shipped with the pack, so a hard browser refresh after a pack update is worth doing if the dialog looks stale. The node itself needs no models; SAM smart-select needs a SAM 2.1 checkpoint and the sam2 package, and edge refine needs ViTMatte weights.

Where people get burned

The masks live on the server, not in the workflow. Send someone your .json and they get an empty mask, because their input/c2c_masks/<editor_id>/ doesn't have your PNGs. Export PNG from the frame menu if you need the mask to travel.

Second: editor_id says "auto-set by the editor UI - don't edit by hand" and it means it. Duplicating a node carries the id; two nodes sharing an id fight over the same stored masks, which looks like the editor randomly reverting frames.

Third: nothing is painted until you open the editor and press Enter to save. The growth stage will happily run on an all-black mask and produce an all-black mask, and it will not be the node's fault.

Category🐺 C2C/🧰 Core/Mask

Inputs (100)

NameTypeDefaultDescription
editor_idSTRINGAuto-set by the editor UI. Don't edit by hand.
frame_modeCOMBOper_frameper_frame: each batch index uses stored frame i; shared: stored frame 0 applies to all.
growINT0-256–256Grow (positive) or shrink (negative) the mask by this many pixels. Any non-zero value makes the edge hard first (every partly covered pixel counts); feather softens it again afterwards.
featherFLOAT00–256Soften the mask edge, in whole pixels (0 = off). Gaussian with sigma = 0.33 x this value, the same feather the Smart Crop/Stitch nodes use.
thresholdFLOAT0.000–1Binarize after feather. 0 = keep soft mask.
invertBOOLEANfalseInvert mask after threshold.
imageoptIMAGEThe picture to draw on (B,H,W,3); drives B/H/W. paint and video need it; points, shape and spline take their size from it when connected.
input_maskoptMASKOptional mask to combine with the painted mask. points + box and shape draw onto it; video uses it on the frames your keyframes do not fill.
combineoptCOMBOreplaceHow painted mask combines with input_mask. Without input_mask only replace applies.
modeoptCOMBOpaintHow the mask is drawn. paint: brush, shapes, lasso, fill and smart select in the editor (and a colour layer); points + box: clicks and boxes for SAM / SeC; shape: a parametric shape; spline: a spline shape or a pattern along it; roto: Bezier shapes keyed over frames; video: painted keyframes, tweened between. Each mode shows only its own controls.
canvas_layeroptCOMBOmask[paint] mask: paint the mask in the editor; colour: paint colour strokes on the canvas (painted_image), their alpha also becomes mask.
canvas_widthoptINT51264–4096[paint: colour] Canvas width in pixels.
canvas_heightoptINT51264–4096[paint: colour] Canvas height in pixels.
canvas_brush_typeoptCOMBOpaint[paint: colour] paint: composite color strokes onto the image. mask_only: build the mask without coloring.
canvas_brush_coloroptSTRING#000000[paint: colour] Hex color used by the paint brush (ignored in mask_only mode).
canvas_brush_opacityoptFLOAT1.000–1[paint: colour] Brush stroke opacity (0 = invisible, 1 = fully opaque).
canvas_brush_hardnessoptFLOAT0.800–1[paint: colour] Brush profile hardness (0 = soft, 1 = hard edge).
canvas_brush_sizeoptINT201–500[paint: colour] Brush diameter in pixels.
canvas_mask_hardnessoptFLOAT0.500–1[paint: colour] Threshold for the solid inner core: pixels brighter than (1 - hardness) clamp to 1.0.
canvas_mask_expansionoptINT0-100–100[paint: colour] Morphological dilate (positive) / erode (negative) in pixels.
canvas_mask_blur_radiusoptFLOAT0.00–100[paint: colour] Gaussian blur radius applied to the mask edge in pixels.
canvas_mask_blur_strengthoptFLOAT1.000–1[paint: colour] Blend factor between the hard mask (0) and the fully-blurred mask (1).
canvas_dataoptSTRING[paint: colour] Internal base64 PNG payload from the JS canvas widget. Do not edit manually.
points_widthoptINT5121–16384[points + box] [draw_*/points_bbox] canvas width
points_heightoptINT5121–16384[points + box] [draw_*/points_bbox] canvas height
points_editor_dataoptSTRING{"points":[],"bboxes":[]}[points + box] JSON from the interactive canvas
points_default_radiusoptFLOAT3.00.5–256[points + box] default brush radius
points_softnessoptFLOAT1.00–10[points + box] gaussian sigma multiplier
points_normalizeoptBOOLEANtrue[points + box] clamp output to [0,1]
shape_inputoptCOMBOparameters[shape] parameters: the shape from the controls below; JSON: the shapes from shape_json (power mode).
shape_widthoptINT5121–16384[shape] [draw_*/points_bbox] canvas width
shape_heightoptINT5121–16384[shape] [draw_*/points_bbox] canvas height
shape_kindoptCOMBOcircle[shape] geometry
shape_cxoptFLOAT256.0-16384–16384[shape]
shape_cyoptFLOAT256.0-16384–16384[shape]
shape_radiusoptFLOAT50.00–8192[shape]
shape_size_woptFLOAT200.00–16384[shape]
shape_size_hoptFLOAT100.00–16384[shape]
shape_rxoptFLOAT100.00–8192[shape]
shape_ryoptFLOAT50.00–8192[shape]
shape_top_left_xoptFLOAT100.0-16384–16384[shape]
shape_top_left_yoptFLOAT100.0-16384–16384[shape]
shape_x2optFLOAT400.0-16384–16384[shape]
shape_y2optFLOAT400.0-16384–16384[shape]
shape_thicknessoptFLOAT5.00–500[shape]
shape_outer_roptFLOAT100.00–8192[shape]
shape_inner_roptFLOAT40.00–8192[shape]
shape_num_pointsoptINT53–50[shape]
shape_corner_radiusoptFLOAT20.00–4096[shape]
shape_cross_sizeoptFLOAT100.00–8192[shape]
shape_arrow_lengthoptFLOAT200.00–16384[shape]
shape_head_lengthoptFLOAT60.00–8192[shape]
shape_head_widthoptFLOAT80.00–8192[shape]
shape_points_jsonoptSTRING[[100,100],[400,100],[400,400],[100,400]][shape] polygon vertices when shape=polygon
shape_valueoptFLOAT1.000–1[shape] fill intensity
shape_rotationoptFLOAT0.0-360–360[shape] rotation deg
shape_operationoptCOMBOset[shape] blend op
shape_batch_sizeoptINT11–256[shape] number of frames
shape_jsonoptSTRING{"cx": 256, "cy": 256, "radius": 50}[shape] raw shape_params JSON (see MaskDrawFrame)
shape_featheroptFLOAT0.00–128[shape] [transform/draw] feather radius
spline_dataoptSTRING[][spline] Spline payload from the JS canvas. edit/flow_path: single shape list. track: keyframes list [{frame:int, points:[[x,y],…]}, …].
spline_typeoptCOMBOcatmull_rom[spline] interpolation method. catmull_rom/natural_cubic/cardinal pass through the points; b_spline/nurbs are smooth approximating curves; bezier uses tangent handles; polyline = straight.
spline_closedoptBOOLEANtrue[spline] closed loop vs open path
spline_samples_per_segmentoptINT202–128[spline] curve resolution per segment
spline_feather_radiusoptFLOAT0.00–64[spline] gaussian edge feather
spline_invertoptBOOLEANfalse[spline] invert mask
spline_smoothingoptBOOLEANtrue[spline] enable spline smoothing
spline_centripetal_alphaoptFLOAT0.500–1[spline] Catmull-Rom alpha (0.5 = centripetal)
spline_widthoptINT00–16384[spline] output width (0 = inherit image)
spline_heightoptINT00–16384[spline] output height (0 = inherit image)
spline_mask_coloroptSTRING#ff00ff[spline] preview overlay color (hex)
spline_mask_opacityoptFLOAT0.400–1[spline] preview overlay opacity
spline_filloptCOMBOmask[spline] mask: fill (closed) or stroke (open) the spline; flow pattern: a procedural pattern along it (ribbon, wave, dust, smoke...), animated over frames.
spline_flow_patternoptCOMBOribbon[spline: flow pattern] procedural pattern
spline_flow_thicknessoptFLOAT12.00–1024[spline: flow pattern] base stroke thickness
spline_flow_amplitudeoptFLOAT8.00–1024[spline: flow pattern] modulation amplitude
spline_flow_frequencyoptFLOAT2.00–64[spline: flow pattern] modulation frequency
spline_flow_turbulenceoptFLOAT0.000–4[spline: flow pattern] noise turbulence strength
spline_flow_turbulence_scaleoptFLOAT1.000.01–32[spline: flow pattern] noise spatial scale
spline_flow_edge_softnessoptFLOAT1.00–32[spline: flow pattern] edge softness in pixels
spline_flow_taper_startoptFLOAT0.000–1[spline: flow pattern] start-end taper amount
spline_flow_taper_endoptFLOAT0.000–1[spline: flow pattern] tail-end taper amount
spline_flow_framesoptINT11–4096[spline: flow pattern] number of animation frames
spline_flow_animation_speedoptFLOAT0.0500–4[spline: flow pattern] phase advance per frame
spline_flow_flow_directionoptCOMBOforward[spline: flow pattern] flow direction
spline_flow_mod_decayoptFLOAT0.000–4[spline: flow pattern] modulation falloff over time
spline_flow_seedoptINT00–4294967295[spline: flow pattern] noise seed
spline_flow_use_embedded_editoroptBOOLEANtrue[spline: flow pattern] show embedded spline preview
roto_jsonoptSTRING{"canvas": {"w": 1024, "h": 1024}, "frames": [{"frame": 0, "splines": []}]}[roto]
roto_frame_countoptINT11–4096[roto]
roto_widthoptINT102416–8192[roto]
roto_heightoptINT102416–8192[roto]
roto_samples_per_segoptINT242–256[roto]
roto_feather_pxoptFLOAT0.00–64[roto]
roto_frameoptINT00–4096[roto] Which keyframe the editor is on. Scrub here, move the shape, and a key is written at this frame. With one key the shape holds for the whole clip; with several the renderer interpolates between them. Does not affect the render on its own.
video_session_idoptSTRING[video] Auto-set by the editor UI. Don't edit by hand.
video_tween_modeoptCOMBOdistance_transform[video] Frames BETWEEN two painted frames: distance_transform morphs the shape, linear blends, hold keeps the previous painted mask, none leaves them unpainted (frame by frame).
video_featheroptFLOAT0.00–32[video] Gaussian feather radius (px). 0 = none.
video_thresholdoptFLOAT0.000–1[video] Binarize after tween. 0 = keep soft mask.
video_outside_keysoptCOMBOempty[video] Frames before the first / after the last painted frame: empty (the mask stays on the frames you painted) or hold the nearest painted mask.

Outputs (12)

NameTypeDescription
maskMASKThe final mask [B,H,W] in 0-1: the active mode's mask, combined with input_mask, then grow, feather, threshold and invert.
previewIMAGEThe input image with the mask tinted over it (the mask as a grey picture without an image).
infoSTRINGFrame count, stored masks, mode and notes (resized frames, frame recording skipped).
positive_coordsSTRINGpoints + box: positive points for SAM / SeC; spline: points along the spline. '[]' otherwise.
negative_coordsSTRINGpoints + box: negative points. '[]' otherwise.
bboxesBBOXpoints + box: the positive boxes. Empty otherwise.
neg_bboxesBBOXpoints + box: the negative boxes. Empty otherwise.
points_jsonSTRINGpoints + box: every point as JSON. '[]' otherwise.
bbox_jsonSTRINGpoints + box: the first positive box [x1,y1,x2,y2]; spline: the spline's box. '[]' otherwise.
primary_bboxBBOXpoints + box: the first positive box [x,y,w,h]; spline: the spline's box. [0,0,0,0] otherwise.
spline_data_outSPLINE_DATAspline: the spline data, for a tracker or another spline node.
painted_imageIMAGEpaint: the colour layer composited over the image (the image itself without colour strokes).