Nodes/comfyui_cv/CV Keep Largest Component
ComfyUI Node

CV Keep Largest Component

Keeps only the single largest connected component of a binary mask (cv2.connectedComponentsWithStats), dropping every smaller blob - the standard way to isolate one object from scattered noise or secondary movers before seeding GrabCut / watershed. Unlike 'Select Component At Point' it needs no probe location: it just takes the biggest blob by area. Failure-tolerant: an empty mask (no foreground) yields found=false and an empty mask, not an error.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Keep Largest Component
  • image
  • mask
  • area
  • found
connectivity8
Categoryimage/CV/contours

Inputs (2)

NameTypeDefaultDescription
imageCOMFY_MATCHTYPE_V3Binary image (or MASK); non-zero = foreground. The mask comes back in this input's format. 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.
connectivityCOMBO88 also connects diagonal pixels; 4 only direct neighbours.

Outputs (3)

NameTypeDescription
maskCOMFY_MATCHTYPE_V30/255 mask of the largest component, in the image input's format.
areaINTPixel area of the kept component (0 if none).
foundBOOLEAN