Nodes/ComfyUI CV/CV Select Component At Point
ComfyUI Node

CV Select Component At Point

'give me the blob that's under this pixel'

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
CV Select Component At Point
  • image
  • mask
  • found
◄x0.00►
◄y0.00►
◄search_radius0.00►

Segmentation gives you a binary image full of blobs. Usually you want exactly one of them, and "the largest" is the wrong heuristic more often than you'd think. CV Select Component At Point asks a better question: which blob is here?

The author's own example is the clearest one. In a clock face, the hands are the only dark blob connected to the dial center; the numerals, the tick marks and the rim are all separate connected components. Probe the center, keep the hands, discard the rest. No area thresholding, no morphology hairball, no tuning.

How it works

It runs connected-component labelling over the binary input and keeps the component(s) that touch your probe point. With search_radius = 0 that's literally one pixel - the exact pixel under (x, y). Raise the radius and it accepts components that touch a disk of that radius around the point, which is what you want when your probe coordinate comes from an upstream centroid that might be a pixel or two off.

That connecting step is where the pack does something worth knowing about: it writes a 0/255 binary mask, not a cropped rectangle. So the region you get back hugs the object's outline. That matters downstream - the KB's masking doc makes the point that a bbox mask leaves a rectangular patch whose seams can show when you re-render it, while a polygon-shaped mask mostly doesn't. Blob-shaped masks are the same family.

What you actually set

  • image - the binary image, or a MASK. Non-zero is foreground. It takes a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY, and it hands the mask back in the format you gave it - so a MASK in, a MASK out, no conversion node in the middle. For a full-batch pass, use it alongside the pack's arithmetic nodes, which do process whole IMAGE batches when both sides match.
  • x, y - the probe point, FLOAT, default 0. Wire these from CV Split Point if what you have is a point tuple, or just type the coordinates you clicked out of a preview.
  • search_radius - FLOAT, default 0, min 0. 0 is the exact-pixel case. A handful of pixels is the forgiving version.

Two outputs: mask (0/255, in the input's format) and found (BOOLEAN). Feed the mask to CV Find Contours, CV Crop by Masks, or straight into an inpaint/refine branch. Branch on found with a control-flow node for the case where your probe missed everything - which the node reports rather than raising, so a workflow with one bad frame doesn't die mid-batch.

Install

ComfyUI Manager → search ComfyUI CV → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Python ≥ 3.12 and a ComfyUI recent enough for the V3 node API. This node needs no model files.

Common issues

  • found is false and the mask is empty. No foreground under the probe - which is a real answer, not a bug. Usually the threshold upstream was too aggressive, or your coordinate is a latent coordinate rather than a pixel one. Scale it first; CV Scale Points and CV Scale BBoxes are the two ways.
  • You got the wrong blob. The component touches your point because a thin bridge connects it to the blob you wanted. Check the mask before the threshold: two blobs merging into one is a morphology problem, not a node problem. connectivity isn't a knob here (CV Keep Largest Component has it, this one doesn't) - the fix is upstream, usually a 4-connectivity erode/erode-open pass.
  • The mask reads black in the preview but the numbers look right. A 0/255 uint8 mask previews as near-black on a dark UI. Run it through the pack's conversion nodes if you want to see it as an image.
  • Everything in image/CV disappears after installing an unrelated pack. A non-contrib OpenCV wheel got pulled in and wiped the contrib submodules in the shared site-packages/cv2. Fix with tools/repair_opencv_contrib.py --check then --apply.
Categoryimage/CV/contours

Inputs (4)

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.
xFLOAT0.00-1000000–1000000X pixel coordinate of the probe point.
yFLOAT0.00-1000000–1000000Y pixel coordinate of the probe point.
search_radiusFLOAT0.000–1000000Also accept components that touch a disk of this radius around (x, y). 0 = the exact pixel only.

Outputs (2)

NameTypeDescription
maskCOMFY_MATCHTYPE_V30/255 mask of the selected component(s), in the image input's format.
foundBOOLEAN—