Nodes/comfyui_cv/CV Connected Components (Split Mask)
ComfyUI Node

CV Connected Components (Split Mask)

Splits a mask into its separate regions (cv2.connectedComponentsWithStats): one MASK per blob as a batch, plus bounding boxes. Chain into 'CV Crop by Masks' to process each region individually (e.g. schedule one inpainting per region); visualize with 'OpenCV Overlay Masks' or the core 'Draw BBoxes' node.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Connected Components (Split Mask)
  • mask
  • region_masks
  • bboxes
  • count
connectivity8
min_area16
max_regions64
sortlargest first
Categoryimage/CV

Inputs (5)

NameTypeDefaultDescription
maskMASKMask to split. A batch is merged (union) before splitting.
connectivityCOMBO88 also connects diagonal pixels; 4 only direct neighbors.
min_areaINT161–2147483647Regions smaller than this many pixels are dropped (removes noise specks).
max_regionsINT641–1024Keep at most this many regions (after sorting).
sortCOMBOlargest firstOrder of the output region masks/boxes: by area (largest first), left-to-right, or top-to-bottom.

Outputs (3)

NameTypeDescription
region_masksMASKOne full-size mask per region, as a MASK batch.
bboxesBOUNDING_BOXCore BOUNDING_BOX data: per-frame lists of {x, y, width, height} dicts - compatible with Draw BBoxes, Crop By Bounding Boxes, Image Crop, etc.
countINT