The textbook way to label takes two passes over a binary image, each one row by row. The StrataQuest reference does not say which method its Label operation uses.
- First pass. Scan rows top to bottom, left to right. At each foreground pixel, look at the neighbors already visited: left and above, plus upper-left and upper-right under 8-connectivity. If none of them is foreground, assign a new label; if one carries a label, copy it; if several carry different labels, assign one of them and record that the labels are equivalent.
- Second pass. Resolve the recorded equivalences with a union-find structure, replacing each temporary label with its canonical one. If later operations leave gaps in the numbering, Re-Label (missing) corrects the label list.
A morphological route reaches the same answer. Dilate from a seed pixel inside one component, constrained to the original foreground, until the growth stops changing; what it covers is the whole component. Clear that component from the working image, increment the label, and repeat until every component has a number.