After thresholding, an image is just lit and unlit pixels — but which lit pixels belong to the SAME object? A flood-fill answers it: touch one bright pixel, spread to every bright neighbour, paint them a colour, and that whole island is one thing. Count the islands and you’ve counted the objects. Slide the cutoff and watch objects split and merge.
Threshold the image, then label: scan for an unlabelled lit pixel, flood-fill its 4-connected region with a fresh label, repeat. Each flood-fill is exactly one object; the count of labels is the object count. A fail-loud self-check runs a fixed image with three separated blobs and throws unless the labeller returns exactly 3 — the segmentation is a graph traversal, deterministic, not an estimate.
4-connectivity here (8-connectivity would merge diagonally-touching blobs); the cutoff is global, so uneven lighting mislabels (watershed/adaptive methods handle that). The flood-fill count is exact for the given binary image.