Every blob tool asks one question before it groups the white pixels of a binarized image into markers: do two pixels that touch only at a corner count as neighbours? Answer yes and the tool runs connectivity 8; answer no and it runs connectivity 4. For filled circular and elliptical markers — fiducials, drilled holes, LED dots, retroreflective targets — the setting almost never changes the result. A solid marker that stands clear of its neighbours is labelled identically under both rules, down to the last pixel of area and centroid. Connectivity only decides outcomes in two narrow situations: a gap of about one pixel between markers, and a one-pixel dropout seam inside a marker. This guide defines both adjacency rules, works the arithmetic for a typical marker pair, and ends with the setting to keep in each case.
What connectivity 4 and connectivity 8 mean
Connected-component labelling scans the foreground of a binary image and hands every pixel to the blob it can reach through neighbour steps. The connectivity setting defines what counts as a neighbour. Under connectivity 4 (the N4 neighbourhood in the segmentation literature), two pixels are neighbours only when they share an edge: up, down, left or right. Under connectivity 8 (N8), the four diagonal corners count as well:
N4 N8
. O . O O O
O X O O X O
. O . O O O
A library applies the rule to whichever pixels are segmented as objects: bright foreground in a white-on-black image, dark regions when the polarity is flipped. Everything below assumes bright markers on a dark background; for dark-on-bright, flip the reasoning and keep the rule.
Why a filled circle barely notices the setting
A rasterized filled disk or ellipse is 4-connected by construction. Each pixel row of a circle is a single horizontal interval centred on the circle's vertical axis, and that interval always contains the pixel column nearest the axis. Neighbouring rows therefore share at least one central column and join edge-to-edge, so no connection inside the shape or along its rim ever relies on a diagonal step.
The consequence is exact, not approximate: for a solid marker isolated from its neighbours, connectivity 4 and connectivity 8 return the identical pixel set. Area, centroid, bounding box and pixel count match to the pixel. If the binarization is clean, the connectivity field in the tool dialog is not worth one tuning iteration. Position accuracy comes from further down the pipeline, and the grayscale centroid method for a dark circle shows how to push the position itself to sub-pixel once the blob is right.
The two cases where the setting changes the answer
Merging. Two markers whose nearest pixels touch corner-to-corner are diagonal neighbours: two blobs under connectivity 4, one blob under connectivity 8. The geometry is fixed — diagonal neighbours sit √2 ≈ 1.41 px apart centre-to-centre, edge neighbours 1 px apart — so the decision band sits at an edge gap between roughly 1 and 1.4 px. Above about 1.5 px both settings keep the pair separate; below about 1 px both merge it. Which setting fires first depends on the subpixel phase of the two facing edges.
Splitting. Threshold dither along a diagonal edge can leave a one-pixel stair-step seam of background pixels crossing a marker. The two sides of such a seam touch only corner-to-corner, so connectivity 8 holds the marker together while connectivity 4 cuts it into fragments. Noisy thresholds on anti-aliased edges produce exactly these seams, so threshold quality comes before connectivity tuning; the adaptive thresholding guide for uneven part shading covers the fix.
Outlines. A one-pixel-wide digital circle steps diagonally along most of its arc. Connectivity 4 shreds such a ring into arc fragments; connectivity 8 keeps it whole. If the tool measures filled blobs only, fill the ring first, then label.
Worked example: two 60 × 40 px ellipse markers 80 px apart
Inputs, all in image pixels (example values for the classic case of filled ellipses in a clean binarized image): each marker is an ellipse 60 px wide and 40 px tall, so semi-axes a = 30 px and b = 20 px; the two markers sit side by side with centre spacing s = 80 px; binarization leaves no dropout seams.
Rule: an ellipse of semi-axes a and b covers A = π a b pixels, and the rasterized count lands within a few pixels of it. Two blobs merge only if at least one pixel pair is adjacent: edge contact under connectivity 4, edge or diagonal contact under connectivity 8.
Arithmetic:
- Area per marker: A = π × 30 px × 20 px = 1884.96 px ≈ 1885 px.
- Edge-to-edge gap: gap = s − 2a = 80 px − 60 px = 20 px.
- Compare with the contact distances: 20 px lies far beyond both 1 px (edge contact) and 1.41 px (diagonal contact), so no pixel pair is adjacent under either rule.
- Output: two blobs of ≈ 1885 px each, each centroid at its true centre, identical for connectivity 4 and connectivity 8.
Decision: at a 20 px gap the setting has zero effect, so keep connectivity 8 and spend no more time on it. The margin that matters is the gap. Shrink the spacing to s = 61.4 px and the gap falls to 1.4 px, where diagonal contact becomes possible. If connectivity 8 merges the pair, the tool reports one blob of 2 × 1885 px = 3770 px whose centroid sits at the midpoint, s/2 = 30.7 px from each true centre, and the marker count reads 1 instead of 2. Connectivity 4 keeps the pair separate until true edge contact below a 1 px gap.
What actually moves the centroid
With connectivity settled for solid markers, three factors own the error budget.
Threshold asymmetry. A brightness ramp across the marker — uneven illumination, a shaded edge — biases the centroid toward the brighter side, typically by tenths of a pixel in an uneven-lighting scene. Balance the lighting or move to an adaptive threshold before touching anything else.
Pixels across the marker. Pixel-level scatter averages down with the square root of the blob's pixel count:
The 1885 px marker from the worked example gives √1885 ≈ 43, so scatter lands near 1/43 ≈ 0.02 px. Shrink the marker to 4 px across and N ≈ π × 2² ≈ 13, so scatter rises to 1/√13 ≈ 0.28 px — more than an order of magnitude worse. That scaling is why fiducial marker pixel size dominates small-marker designs, and the trade-offs of shrinking the pixel itself sit in small pixel camera selection.
Sampling and focus. Put at least 10 px across the smallest marker; below about 5 px, threshold phase dominates repeatability. The sensor requirement is modest: for a 120 mm field of view holding a 4 mm marker, the sensor needs (120 mm ÷ 4 mm) × 10 px = 300 px across the field, a bar even a 640 × 480 sensor clears. The camera resolution calculator runs the conversion on your own field of view:
For PC-side analysis, a 4000 × 3000 sensor over that same 120 mm field delivers 4000 px ÷ 120 mm ≈ 33 px/mm, so the 4 mm marker spans 33 px/mm × 4 mm ≈ 133 px. The LS-CMR-0166 is one such 4000 × 3000 USB3 camera.
- Sensor format
- 1/1.7"
- Interface
- USB3
- Resolution
- 12 MP
- Shutter
- Rolling
Which setting to keep, per case
- Filled circular or elliptical markers, isolated: keep connectivity 8. The two settings return identical blobs, and 8 also survives one-pixel dropout seams on diagonal edges.
- Markers that can drift within about 1.5 px of each other: widen the gap first, with more magnification, a tighter threshold or better lighting. If the geometry cannot change, connectivity 4 protects the count down to a 1 px gap.
- Dense dot arrays, halftones and closely packed holes that touch corner-to-corner: connectivity 4, chosen deliberately, so each feature stays counted separately.
- One-pixel-wide rings and outlines: connectivity 8, or fill the outline and measure the filled disk.
- Streaks and other features joined diagonally that must stay single: connectivity 8.
Checks before you trust the output
- Run the tool once at connectivity 4 and once at connectivity 8 across a dozen production images, then diff marker count, area and centroid per marker. Identical output closes the question for your scene in minutes.
- Measure the smallest background gap between markers on a worst-case image. At 2 px or more, neither setting can merge the pair; below about 1.5 px, fix the optics or the threshold first.
- Zoom to 1:1 on diagonal edges and look for one-pixel dropout seams. If they appear, adjust the threshold or close the image with a small structuring element; this matters most when you must run connectivity 4.
- Confirm the polarity setting: white-on-black versus black-on-white decides which pixel population the adjacency rule governs.
- Watch the marker count over a shift. A count alternating between n and n − 1 signals a marginal gap; a count alternating between n and n + 1 signals a splitting seam.
Cameras that run the labelling on the device
On the line, smart cameras and vision sensors run thresholding, connected-component labelling and blob measurement on board, and the camera finder filters them by resolution, shutter, lens mount and interface. The MV-SC3050XC-16M-ATN-H inspects with a 5 MP global-shutter sensor in M12 mount over Fast Ethernet. The MV-SC5060XM-08M-WBN pairs a 6 MP mono sensor with an integrated 8 mm M12 lens on GigE. The LS-SMC-0063 reads out at 60 fps through an integrated 16 mm lens with built-in white light.
- Interface
- Fast Ethernet
- Resolution
- 5 MP
- Interface
- GigE
- Resolution
- 6-10 MP
- Interface
- GigE
- Resolution
- Up to 3 MP
For PC-side analysis with full control over the labelling step, area scan cameras over GigE or USB3 hand you the frame and you run the algorithm yourself. The camera configurator pairs the sensor with a lens for your working distance.
When the usual advice is wrong
'Connectivity 4 is more accurate.' On a clean solid marker both settings select the same pixels, so there is no accuracy to gain. Centroid precision comes from threshold symmetry, focus and pixel count.
'Connectivity 8 is risky because it merges blobs.' The merge needs a gap under about 1.4 px. In a correctly sized scene it never fires, while 8's tolerance of diagonal dropout seams saves blobs on every shift.
'Tune connectivity to fix flickering blobs.' The adjacency rule only decides single-pixel events; if blobs flicker, the threshold or the resolution is wrong. And if markers genuinely overlap, no adjacency rule separates them — a contour-based circle detector or a Hough-transform detector works from edges instead of pixel adjacency.
The decision
For filled circular markers on a contrasting background: keep connectivity 8, put at least 10 px across each marker, hold marker-to-marker gaps at 2 px minimum and 5 px or more comfortably, and settle the question once by diffing both settings on a dozen real images. Switch to connectivity 4 only when features legitimately touch corner-to-corner and must be counted separately.
The tenths of a pixel you are chasing live in threshold symmetry, focus and pixel count, not in the adjacency rule. The length-measurement calibration from image markers takes over once blob positions are trustworthy, and more system-side reading sits on the machine-vision systems topic page.
If you want the labelling to run on the camera itself, start from the smart camera filters above; for a build list checked against your marker sizes and cycle rate, send the details and we will spec the chain.
Questions
Does connectivity 4 ever give a more accurate centroid than connectivity 8?
No. For a filled marker that stands clear of its neighbours, both settings select the identical pixel set, so area and centroid match to the pixel. Position accuracy is set by threshold symmetry, focus and the number of pixels across the marker; the adjacency rule contributes nothing until single-pixel gaps or dropout seams appear in the binarized image.
When is connectivity 4 the deliberate choice?
When two foreground features can touch corner-to-corner and must be counted separately: dense dot arrays, printed halftone patterns, closely packed holes. In those scenes connectivity 8 fuses any pair whose rims meet diagonally, which halves the count and pulls each reported centroid to the midpoint of the merged pair. For every other marker case, connectivity 8 is the safer default.
Does the connectivity setting apply to dark regions too?
It applies to whichever pixels the tool treats as objects. On a white-on-black binarization that is the bright foreground; flip the polarity to dark-on-bright and the same adjacency rule governs the dark regions, so a hole-detection tool behaves identically. When counts change unexpectedly, check polarity first — an inverted image silently moves the rule from the markers to the background.
Why does my thin ring marker break into arc fragments?
A one-pixel-wide digital circle steps diagonally along most of its path, and connectivity 4 does not follow diagonal steps, so the ring shatters wherever it steps cornerwise. Run connectivity 8, draw or etch the ring at least two pixels wide, or fill the outline first and measure the filled disk. The same applies to thin elliptical outlines.
How many pixels across a marker are needed for a repeatable centroid?
Plan for at least 10 px across the smallest marker. Centroid scatter falls with the square root of the pixel count: a 40 px diameter marker holds about π × 20² ≈ 1257 px, so pixel-level noise averages down by a factor near 35, leaving errors in the hundredths of a pixel. Below about 5 px, threshold phase dominates and repeatability collapses.



