Nodes/comfyui_cv/CV Components Touching Border
ComfyUI Node

CV Components Touching Border

Keeps every connected component of a binary mask that reaches a chosen image edge - or, with mode = 'remove', everything that does NOT. Touching the frame edge is what separates unbounded background (sky, a table surface, water) from bounded objects, and the inverse is the usual way to drop detections the frame clipped. Neither 'Keep Largest Component' nor 'Select Component At Point' can express it: the largest blob is often something else entirely, and one probe point catches one component, while a background region is routinely cut into many by whatever crosses it. Failure-tolerant: an empty mask (or one where nothing touches the chosen edge) yields an empty mask and found=false, not an error.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Components Touching Border
  • image
  • mask
  • area
  • count
  • found
borderany edge
modekeep touching
connectivity8
margin0
Categoryimage/CV/contours

Inputs (5)

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.
borderCOMBOany edgeWhich image edge a component must reach to count.
modeCOMBOkeep touching'keep touching' isolates the background that runs off the frame; 'remove touching' drops blobs the frame cut off and keeps the fully-visible ones.
connectivityoptCOMBO88 also connects diagonal pixels; 4 only direct neighbours.
marginoptINT00–64How many pixels in from the edge still count as 'the border'. It has to cover whatever artefact the frame edge already carries, or a region that visually reaches the edge is missed entirely: cv2.remap with BORDER_CONSTANT leaves a dark seam one row deep, and any blur/derivative applied after it smears that seam a few rows further, so a mask derived from gradients may only start answering at row 4. Morphology is NOT the problem - OpenCV pads erosion with +inf, so an opening does not shrink a region at the image border.

Outputs (4)

NameTypeDescription
maskCOMFY_MATCHTYPE_V30/255 mask of the kept components, in the image input's format.
areaINTTotal pixel area kept.
countINTHow many components were kept.
foundBOOLEANFalse when nothing was kept (empty mask out).