Nodes/comfyui_cv/CV GrabCut
ComfyUI Node

CV GrabCut

Interactive-style foreground extraction (cv2.grabCut): give it a rough hint of where the object is and it refines the boundary from color statistics. Hints, combinable: 'points' (2 or more, e.g. from 'OpenCV Annotate Points') mark the object's bounding rectangle - everything outside is sure background; 'mask' marks probable foreground (the annotate node's polygon output fits directly); sure_foreground / sure_background scribbles pin pixels that must keep their side. Outputs the foreground as a 0/255 mask plus the raw 4-value label map (sure/probable x fg/bg - view with 'Preview CV Array' in heatmap mode). Failure-tolerant: with no usable hints, or when everything ends up background, success=false and an empty mask come out instead of an error - branch on success with an if/else node.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV GrabCut
  • image
  • points
  • mask
  • sure_foreground
  • sure_background
  • mask
  • labels
  • success
iterations5
Categoryimage/CV/segmentation

Inputs (6)

NameTypeDefaultDescription
imageNPARRAY,IMAGEColor image (BGR uint8); grabCut needs 3 channels - grayscale is converted. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
iterationsINT51–50GrabCut refinement iterations; 5 is usually plenty.
pointsoptNPARRAY2+ points whose bounding rectangle contains the object (Nx1x2 or Nx2). Everything outside the rectangle becomes sure background.
maskoptNPARRAY,MASKMask; non-zero = probable FOREGROUND (the rest stays probable background unless 'points' also marks a rectangle). The polygon mask of 'CV Annotate Points' plugs in directly. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
sure_foregroundoptNPARRAY,MASKScribble mask; non-zero pixels are forced to stay foreground. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
sure_backgroundoptNPARRAY,MASKScribble mask; non-zero pixels are forced to stay background. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.

Outputs (3)

NameTypeDescription
maskNPARRAYuint8 0/255 foreground mask (sure + probable foreground).
labelsNPARRAYRaw GC label map: 0 sure BG, 1 sure FG, 2 probable BG, 3 probable FG - view with 'Preview CV Array' (heatmap).
successBOOLEAN