[mmdFlow] [Up] [mmdHolecenter] Demonstrations

mmdGear
Detect the teeth of a gear

Description

The input image is a binary image of a gear. The opening top-hat is used to detect the gear teeth. Finally, the teeth detected are labeled.

Illustrated Source Code

Reading

The binary image of a gear is read.

Image a = mmReadgray("gear.tif");
mmShow(a);

a

Opening and subtraction

Opening of the input image by an Euclidean disk of radius 20. The sequence opening-subtraction is called opening top-hat. The opening top-hat could be executed in a single command: c = mmOpenth (a,mmSedisk (20));

Image b = mmOpen(a, mmSedisk(20));
mmShow(b);
Image c = mmSubm(a, b);
mmShow(c);

b c

Labeling and counting

The teeth detected are labeled. The maximum pixel value in the labeled image gives the number of connected objects (n. of teeth).

Image d = mmLabel(c);
int nteeth = (int)mmStats(d, "max");
printf("nteeth = %d\n", nteeth);
mmLblshow(d, "border");

nteeth = 24

d

[mmdFlow] [Up] [mmdHolecenter]