Explainer · Inspection technology

How do you separate touching eggs in an image with watershed?

Watershed is an algorithm that separates touching objects in an image. When two eggs touch, they form a single blob. Vigiovo finds the centre of each egg with the distance transform, picks one peak per egg, and lets watershed trace the boundary between them, but only on blobs larger than one egg.

Updated · 4 min read

What is watershed and why does it suit eggs?

Watershed is a segmentation algorithm that treats the image as a landscape and floods it from starting points called seeds. Where two basins meet, the boundary between two objects appears. For eggs this solves a common problem: two touching shells look like one blob, and a colour mask alone cannot separate them.

The idea is simple: one seed per egg, and a flood that stops at the boundary with the neighbouring egg. The hard part is finding those seeds reliably, and that is what the two steps below do.

How does the distance transform find the centre of each egg?

The distance transform replaces each pixel of the blob with its distance to the nearest edge. The result is a map in which the centre of each egg becomes a peak, because it is the point furthest from any edge.

When two eggs touch, the map has two peaks joined by a valley, right where one shell meets the other. The watershed traces the division along that valley.

Why use h-maxima instead of every peak?

H-maxima are peaks that stand at least h above their surroundings. Vigiovo uses them to find exactly one peak per egg, through morphological reconstruction.

Without this filter, any small irregularity in the shell would create an extra peak, and one egg would be cut in two. With h-maxima, only peaks that genuinely stand out become seeds.

When does Vigiovo apply watershed?

Only on blobs that contain more than one egg. A blob the size of a single egg skips the split, which saves processing and avoids unnecessary cuts. The table sums up the steps in the order the system runs them.

These steps apply to each grouped blob, not to the whole image.

Steps for separating touching eggs
StepInputOutput
Colour maskConveyor imageShell blobs
Distance transformBlob with two or more eggsMap in which each centre is a peak
H-maximaDistance mapOne seed per egg
WatershedSeeds and distance mapBoundary between each pair of eggs

What happens when the split does not work?

The egg gets no grade. Vigiovo marks as unverified any egg it cannot see whole, or that does not look like an egg after the split. That happens when:

  • the egg touches the image border;
  • its area falls outside the range of 0.35 to 2.5 times that of a typical egg;
  • its solidity is below 0.90, which indicates a concave shape and possible overlap;
  • its outline does not look like an ellipse or the axis ratio is above 1.8.

This is the honest limit of the method. Two overlapping eggs, one covering part of the other, do not have a boundary that a flat image reveals with certainty. Instead of guessing, the system does not grade the egg and sends it to manual checking. An ungraded egg costs less than a wrong grade.

Frequently asked questions

Is watershed applied to every egg on the conveyor?

No. It runs only on blobs that contain more than one egg. A single egg forms one region and does not need to be separated, so the step is skipped. This rule saves processing and avoids unnecessary cuts in eggs that are already separate.

What happens to two eggs that overlap?

A boundary-based split does not guarantee the correct division when one egg covers part of another. If the resulting shape is concave, touches the image border or falls outside the typical size, the egg is marked unverified, receives no grade and goes to manual checking.

Is the egg separation always the same for the same image?

Yes. The method uses fixed rules, with no trained model and no randomness. The same image with the same configuration produces the same seeds and the same boundaries, which makes every decision possible to audit afterwards.

Sources

  1. Watershed segmentation, scikit-image
  2. Image Segmentation with Watershed Algorithm, OpenCV documentation
  3. Como o Vigiovo classifica ovos sem IA / How Vigiovo grades eggs without AI, Vigiovo

How Vigiovo helps

Vigiovo grades eggs on the conveyor as clean, dirty, cracked or unverified, in real time, with deterministic computer vision: every decision comes with the measurements behind it, on an ordinary CPU.

See how it works