Connected Components With Stats π¦
Count the blobs in your binary image, with their stats
- Np_bin
- num_labels
- labels
- stats
- centroids
Connected components is the computer-vision answer to "how many separate things are in this binary image, and what are their sizes and positions?" After you threshold or edge-detect, every region of touching non-zero pixels becomes one component. This node runs OpenCV's connectedComponentsWithStats and hands you a count plus per-component geometry - which is the foundation for counting objects, sizing regions, or filtering by area.
What it gives you
Four outputs, which is unusually generous:
num_labels(INT): how many components were found (including background, which is usually label 0).labels(NPARRAY): an image where every pixel is stamped with its component's ID - 0 for background, 1..N for each blob. Segmenting by this is how you'd mask a single detected object.stats(any): the per-component statistics table - bounding box x/y, width, height, and area for every label. This is the node's superpower: filter blobs by area, find the biggest one, drop everything smaller than a threshold.centroids(any): per-component centroid coordinates (x, y), useful for measuring or for drawing markers.
The inputs
Np_bin: a binary NPARRAY - non-zero pixels are "1". The tooltip says it plainly: make it with compare, threshold, inRange, Canny, etc. from this pack's own OpenCV set.connectivity(4 or 8, default 8): whether diagonal neighbors count as connected. 8 connects more aggressively; 4 only cardinal directions.removeSurrounding(default true): if a region touches three-plus corners of the frame, it's treated as the image's surrounding background and removed from the output. It's a nice touch - it stops your detector from counting "the whole photo's border" as an object.
The one big constraint
This node is single-batch only. Feed it a batch of images and it raises a ValueError; the source literally checks Np_bin.shape[0] != 1. Same story as the pack's Find/Draw Contours nodes. If you get that error, that's what it means - run one image at a time.
Also: if num_labels <= 1 (i.e. nothing was found), it raises "No objects found in the binary image." Not a warning - an exception. If your image has no blobs, this node fails loudly. That's arguably correct behavior for a detector, but expect it when you feed a blank threshold result.
The workflow it belongs to
Image β To Nparray β threshold/Canny β Connected Components With Stats β use stats/centroids to filter or measure, and labels to mask individual components. In this pack's world you'd then feed centroids into Draw Circles to mark what you found.
Install
ComfyUI Manager β search ComfyUI-ArchiGraph, or:
cd ComfyUI/custom_nodes
git clone https://github.com/vincentfs/ComfyUI-ArchiGraph
Restart and run the pack's install script once. OpenCV is the only real dependency; no models.
Verdict
The stats output is what makes this worth reaching for over a plain label map - area filtering turns a naive blob count into "the three biggest regions, their bounding boxes, and their centers." Just remember it's single-image and it errors when it finds nothing.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| Np_bin | NPARRAY | Single batch binary image. Non-zero pixels are treated as 1's. You can use compare(), threshold(), inRange(), Canny() etc. to create a binary image. | |
| connectivity | COMBO | 8 | Pixel connectivity to use. |
| removeSurrounding | BOOLEAN | true | If true, the surrounding part (different from background) will be removed from output. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| num_labels | INT | β |
| labels | NPARRAY | β |
| stats | * | β |
| centroids | * | β |