A robot inspection pipeline can label the same unchanged patch of foreground with a different integer when another region appears elsewhere in the image. Treating that integer as a persistent part or defect ID can attach a later measurement to the wrong record. A connected-component result identifies regions within its own labeled image; cross-image identity needs another decision.

This article examines that boundary with two original binary arrays. The installed OpenCV runtime reported version 5.0.0. The reference page inspected for the API was OpenCV 4.13.0, and the implementation reference was its public 4.x source branch. The local results below describe the tested runtime, rather than claiming those references certify that binary or any production inspection system.

Keep region membership and numbering separate

OpenCV's connectedComponentsWithStats documentation describes label zero as background, with statistics and centroids indexed by label. It also distinguishes labeling algorithms: SAUF enforces row-major label ordering, while BBDT and Spaghetti do not impose that ordering. Those statements describe the labeling interface and ordering, not a persistent object association contract.

In the proposed inspection record, keep the input mask identity, the labeling configuration, and the label integer together. A label value by itself lacks the image that gives it meaning. If a report stores only region 1 and an area, another labeling result can reuse that same integer for a different region.

Run an example with unchanged connectivity

The first synthetic mask is eight rows by ten columns. It contains one two-by-two foreground block at zero-based rows 5 and 6, columns 6 and 7. All other pixels are background. The second mask retains that block exactly and adds a separate two-by-two block at rows 1 and 2, columns 1 and 2.

Both calls use eight-way connectivity, a CV_32S label image, and the explicit CCL_SAUF algorithm. The first call returns two labels including background, with the lower-right block labeled 1. The second returns three labels including background. Its new upper-left block is label 1, and the unchanged lower-right block becomes label 2.

The retained block has area four in both results and centroid x=6.5, y=5.5 in both. Its pixels did not move, split, or change membership. The additional component changed the enumeration context. These are executed array results, not observations of a moving part or a camera's segmentation accuracy.

Why deterministic ordering does not establish identity

Selecting an algorithm with documented ordering can help reproduce the numbering for a fixed input and configuration. It does not make the first region in every new image the same physical object. The synthetic example already changes the retained region's number while using the same algorithm and connectivity throughout.

A regression test that compares label arrays byte for byte therefore asks a stronger question than whether their foreground partitions agree. When evaluating an implementation change, first decide whether exact numeric labels are part of the required output contract. If they are not, compare region membership through a documented correspondence before interpreting a number change as a segmentation error.

The converse matters too. An unchanged integer does not establish unchanged membership. In the example, label 1 exists in both outputs, but it refers to different foreground blocks. A dashboard that joins records solely on that integer can show a plausible continuity that the labeling operation never established.

Read measurements from the matching result

The OpenCV source inspected for this article builds per-label statistics and centroid output during labeling. Its statistics operator accumulates pixel coordinates and area under the active label. This supports a narrow operational rule: select the statistics row using the label from the matching output, rather than a row number remembered from another mask.

For the first array, the retained region's measurements are in row 1. For the second, they are in row 2. Fetching row 1 after the second call obtains the newly added region's measurements. Equal areas in this deliberately symmetric example would not reveal the mistaken join; the different centroid provides an additional check.

Preserve the mask or its approved immutable reference, labeling parameters, output identity, selected label, and measurement fields in the inspection receipt. Keep any later tracking identifier in another field. That separation makes it possible to review whether an error occurred during segmentation, measurement selection, or cross-frame association.

Define association at the application layer

An inspection system may associate regions using spatial relationships, part fixtures, appearance, acquisition order, or a dedicated tracking method. The appropriate method depends on what the region represents and how the scene can change. This article does not validate a matching rule from the two toy arrays.

When an association is ambiguous, retain that outcome instead of forcing continuity because a label number looks familiar. A split, merge, occlusion, or new foreground region can require an explicit policy. The receipt should identify the method and the evidence used to assign a tracking ID, rather than presenting a component number as proof.

Keep the debugging fixture small

For a focused review, preserve the two masks and both outputs, then check the retained block's pixel support, selected label, area, and centroid. Keep connectivity fixed so that a numbering change is not confused with a different definition of which pixels connect. Record the actual library version used for the calls.

The synthetic result provides a useful failure case for an inspection-data join: the retained region changes from label 1 to label 2, while label 1 is reused for the new region. A correct reporting design can explain both facts without claiming that a physical part changed identity or that the labeling algorithm malfunctioned.

Sources checked November 18, 2026:

OpenCV 4.13.0, Structural Analysis and Shape Descriptors, connectedComponentsWithStats:

https://docs.opencv.org/4.13.0/d3/dc0/group__imgproc__shape.html

OpenCV maintainers, connectedcomponents.cpp, 4.x source branch inspected on the check date:

https://github.com/opencv/opencv/blob/4.x/modules/imgproc/src/connectedcomponents.cpp

The two arrays, executed fixture, and inspection-receipt proposal are original T-800 editorial work. No camera stream, tracking method, robot, or production defect detector was tested.

Illustration: an AI-generated concept shows an unchanged lower-right region receiving a different component number after a new upper-left region is added. It is a schematic of synthetic masks, not a real inspection image.