Explainer · Inspection technology

How do you detect cracks in eggs with image processing?

Black-hat and top-hat filters are mathematical morphology operations that highlight thin lines darker or lighter than their surroundings. Applied to each egg's shell, they bring out cracks as elongated lines. In Vigiovo, a line only counts as a crack if it is elongated, long and deep enough to run into the shell, and the egg is graded cracked when the total length reaches 0.8 of the radius.

Updated · 4 min read

What are black-hat and top-hat filters?

They are two mathematical morphology operations that compare each pixel with its neighbourhood. The black-hat filter highlights lines that are darker than the background around them. The top-hat filter does the opposite and highlights lighter lines. Both use a reference shape, called a structuring element, which sets the thickness of the lines they pick out.

The idea is simple: a thin line is narrower than the reference shape, so it survives in the result, while the smooth areas around it are removed. For the mathematical background in more depth, see mathematical morphology in inspection.

Why do these filters find cracks in the shell?

A crack appears on the shell as a thin line, darker or lighter than the rest of the shell. Because the line is narrow, the filter picks it out without needing labelled examples: what matters is the shape of the defect, not how one particular egg looks.

The problem is that the shell also has other thin lines and shapes that are not cracks, such as round stains and the natural shading near the rim. That is why Vigiovo does not stop at the filter: it applies shape rules to the lines it finds. To understand how each egg's light level is estimated, see the shading surface.

Which rules separate a crack from a stain?

A line only counts as a crack when it meets all three conditions below. Measurements are taken against the egg's reference radius, called r:

  • Elongated: at least 5 times longer than wide.
  • Long: at least 0.35 r.
  • Deep: it reaches at least 0.4 r into the shell, instead of following the rim.

These rules separate cracks from round stains, which are not elongated, and from the natural shading at the rim, which does not run into the shell. A line that fails any of the three conditions does not count toward the egg.

How does the total length become the egg's grade?

Vigiovo adds up the length of the lines that pass the rules. If the total reaches 0.8 r, the egg is graded cracked. The limits are fixed: the same image always gives the same result, and each decision can be checked against the measurements behind it.

Vigiovo crack thresholds and their practical role (practical assessment)
RuleThreshold in VigiovoPractical role
ElongationAt least 5 times longer than wideSeparates cracks from round stains
LengthAt least 0.35 rDrops short scratches
DepthAt least 0.4 r into the shellDrops shading at the rim
Total length0.8 r or moreGrades the egg as cracked

These values are configuration settings, tuned during the calibration of each line with labelled eggs. They are not a legal standard or a regulatory requirement: they mark the point where the line decides a crack is large enough to change the egg's class.

What can this approach not see?

The analysis only sees what is in the camera image. Hairline cracks, invisible under normal light, do not appear as lines and are outside the reach of the method. For those cases, candling or acoustic crack testing are the appropriate methods.

Lighting matters too. Strong glare can look like lines, and shadows can change the contrast of the shell. Diffuse, even lighting reduces that risk more than any parameter setting. Details on how Vigiovo measures the shell are on how it works.

Frequently asked questions

Are black-hat and top-hat filters machine learning?

No. They are mathematical morphology operations with fixed rules and no training. Applied to the same image, they always produce the same result. In Vigiovo, the thresholds for length and depth set in the configuration decide whether an egg is cracked, not a trained model.

Can these filters find hairline cracks?

Not reliably. Hairline cracks are too fine to show under normal light, so a surface camera does not see them. For those, candling or acoustic testing are the suitable methods.

Is the 0.8 radius limit a legal standard?

No. The total crack length limit is a Vigiovo configuration value, tuned during the calibration of each line with labelled eggs. It is not a law or a regulation, and it should be checked against each establishment's own routine.

Sources

  1. Morphological Transformations, OpenCV documentation
  2. 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