Nodes/ComfyUI-CustomNodePacks/Mask Edit — Transform/Draw/Points/BBox
ComfyUI Node

Mask Edit — Transform/Draw/Points/BBox

One node for every mask-editing job — transform, draw, points, bboxes

By Code2Collapse·Created 8 months ago·Updated about 7 hours ago· 58
Mask Edit — Transform/Draw/Points/BBox
  • mask
  • reference_image
  • existing_mask
  • mask
  • positive_coords
  • negative_coords
  • bboxes
  • neg_bboxes
  • points_json
  • bbox_json
  • primary_bbox
◄modetransform►
◄expand_x0►
◄expand_y0►
◄blur_x0.0►
◄blur_y0.0►
◄offset_x0►
◄offset_y0►
◄feather0.0►
◄threshold0.50►
◄invertfalse►
◄width512►
◄height512►
◄shapecircle►
◄cx256.0►
◄cy256.0►
◄radius50.0►
◄size_w200.0►
◄size_h100.0►
◄rx100.0►
◄ry50.0►
◄top_left_x100.0►
◄top_left_y100.0►
◄x2400.0►
◄y2400.0►
◄thickness5.0►
◄outer_r100.0►
◄inner_r40.0►
◄num_points5►
◄corner_radius20.0►
◄cross_size100.0►
◄arrow_length200.0►
◄head_length60.0►
◄head_width80.0►
◄points_json_shape[[100,100],[400,100],[400,400],[100,400]]►
◄value1.00►
◄rotation0.0►
◄operationset►
◄batch_size1►
◄shape_params_json{"cx": 256, "cy": 256, "radius": 50}►
◄editor_data{"points":[],"bboxes":[]}►
◄default_radius3.0►
◄softness1.0►
◄normalizetrue►
◄bboxes_json[]►
◄smoothing_radius3►
◄smoothing_methodmedian_then_exponential►
◄alpha0.30►

Mask Edit (MEC) is the swiss-army knife of this pack: one node, five editing modes, and an eight-port output schema that stays the same no matter which mode you're in. It's a dispatcher - pick a mode and the corresponding widgets drive the engine. Transform a mask, draw a shape, place SAM points, or smooth a bounding-box track, all from the same node.

The reason it exists: the pack's README points out that legacy mask editing scattered the same job across half a dozen nodes. This one collapses them. If you're not sure which MEC editing node to use, start here.

The five modes

  • transform - the workhorse. Feeds on a mask input and does per-axis morphing and shifting: expand_x/expand_y (dilate/erode, negative erodes), blur_x/blur_y (directional Gaussian), offset_x/offset_y (translate), plus feather, threshold (binarize), and invert. It's the quick "grow the mask 8 pixels" or "feather the edge" fix you'll reach for constantly.
  • draw_shape - 12 shapes from a dropdown (circle, rectangle, ellipse, polygon, line, triangle, star, diamond, cross, rounded rectangle, heart, arrow) with named params: center, radius, size, rotation, thickness, value (fill intensity), and an operation blend (set/add/subtract/max/min). There's a batch_size for making N frames of the shape - handy for a video wipe.
  • draw_advanced - the power version: raw shape_params_json for anything the named params don't cover.
  • points_bbox - the interactive canvas mode. The editor_data JSON carries your points and boxes from the JS widget (wire a reference_image and the canvas draws on it), and the node emits SAM-ready outputs.
  • bbox_smooth - temporal smoothing for a sequence of [x,y,w,h] boxes, via bboxes_json, smoothing_radius, smoothing_method, and alpha. The fix for a jittery tracker.

Because it's pure CPU, it's instant - no GPU, no models.

Outputs that matter

The 8-port schema is fixed, which makes downstream wiring stable regardless of mode: mask, then SAM-facing data - positive_coords, negative_coords, points_json, bbox_json - plus bboxes, neg_bboxes, and primary_bbox. In points_bbox mode these feed straight into the pack's SAM nodes (or MaskOpsMEC) as point/box prompts. In other modes the ones that don't apply come back empty or zeroed, so don't panic at a [].

Install

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

or ComfyUI Manager → search "CustomNodePacks", restart, confirm [MEC] Loaded ... in the console. No extra dependencies. One gotcha from the tooltips worth internalizing: transform requires a wired mask; if you switch to it without one, nothing comes out the mask port. And remember presets override sliders in the keying nodes - here the mode dropdown decides which widgets are honored at all.

CategoryMaskEditControl/Edit

Inputs (50)

NameTypeDefaultDescription
modeCOMBOtransformtransform: morph / blur / offset / feather / threshold (needs mask). draw_shape: pick a shape from a dropdown, set its params (12 shapes). draw_advanced: power-mode shape_params_json (raw JSON). points_bbox: interactive points + bbox canvas (SAM/SeC coords). bbox_smooth: temporally smooth a sequence of [x,y,w,h] boxes.
expand_xINT0-512–512[transform] dilate/erode along X
expand_yINT0-512–512[transform] dilate/erode along Y
blur_xFLOAT0.00–128[transform] Gaussian sigma X
blur_yFLOAT0.00–128[transform] Gaussian sigma Y
offset_xINT0-4096–4096[transform] pixel shift X
offset_yINT0-4096–4096[transform] pixel shift Y
featherFLOAT0.00–128[transform/draw] feather radius
thresholdFLOAT0.500–1[transform] binarize threshold
invertBOOLEANfalse[transform] invert output
widthINT5121–16384[draw_*/points_bbox] canvas width
heightINT5121–16384[draw_*/points_bbox] canvas height
shapeCOMBOcircle[draw_shape] geometry
cxFLOAT256.0-16384–16384—
cyFLOAT256.0-16384–16384—
radiusFLOAT50.00–8192—
size_wFLOAT200.00–16384—
size_hFLOAT100.00–16384—
rxFLOAT100.00–8192—
ryFLOAT50.00–8192—
top_left_xFLOAT100.0-16384–16384—
top_left_yFLOAT100.0-16384–16384—
x2FLOAT400.0-16384–16384—
y2FLOAT400.0-16384–16384—
thicknessFLOAT5.00–500—
outer_rFLOAT100.00–8192—
inner_rFLOAT40.00–8192—
num_pointsINT53–50—
corner_radiusFLOAT20.00–4096—
cross_sizeFLOAT100.00–8192—
arrow_lengthFLOAT200.00–16384—
head_lengthFLOAT60.00–8192—
head_widthFLOAT80.00–8192—
points_json_shapeSTRING[[100,100],[400,100],[400,400],[100,400]][draw_shape] polygon vertices when shape=polygon
valueFLOAT1.000–1[draw_*] fill intensity
rotationFLOAT0.0-360–360[draw_*] rotation deg
operationCOMBOset[draw_*] blend op
batch_sizeINT11–256[draw_shape] number of frames
shape_params_jsonSTRING{"cx": 256, "cy": 256, "radius": 50}[draw_advanced] raw shape_params JSON (see MaskDrawFrame)
editor_dataSTRING{"points":[],"bboxes":[]}[points_bbox] JSON from the interactive canvas
default_radiusFLOAT3.00.5–256[points_bbox] default brush radius
softnessFLOAT1.00–10[points_bbox] gaussian sigma multiplier
normalizeBOOLEANtrue[points_bbox] clamp output to [0,1]
bboxes_jsonSTRING[][bbox_smooth] JSON array of [x,y,w,h] per frame
smoothing_radiusINT31–30[bbox_smooth] window radius
smoothing_methodCOMBOmedian_then_exponential[bbox_smooth] smoothing strategy
alphaFLOAT0.300.05–1[bbox_smooth] exponential factor
maskoptMASKSource mask (transform requires this)
reference_imageoptIMAGEOptional reference; canvas size matches it when supplied
existing_maskoptMASKExisting mask to blend onto in draw modes

Outputs (8)

NameTypeDescription
maskMASKRendered mask for the active mode (zero-mask in bbox_smooth mode).
positive_coordsSTRINGPositive points JSON (points_bbox mode); '[]' otherwise.
negative_coordsSTRINGNegative points JSON (points_bbox mode); '[]' otherwise.
bboxesBBOXPositive bbox list (points_bbox); single-element list in bbox_smooth.
neg_bboxesBBOXNegative bbox list (points_bbox mode).
points_jsonSTRINGAll points JSON (points_bbox); '[]' otherwise.
bbox_jsonSTRINGAll bbox JSON (points_bbox) or smoothed bboxes JSON (bbox_smooth).
primary_bboxBBOXPrimary [x,y,w,h]: first positive bbox or smoothed first bbox.