Detect the teeth of a gear
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.
The binary image of a gear is read.
1. a = adreadgray('gear.tif'); 2. adshow(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 = iaopenth(a,iasedisk(20));
1. import ia870 as mm 2. 3. b = mm.iaopen(a,mm.iasedisk(20)); 4. adshow(b); 5. c = mm.iasubm(a,b); 6. adshow(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).
1. d = mm.ialabel(c); 2. nteeth = d.max() 3. adshow(mm.iaglblshow(d,'border'), '%d teeth' % nteeth )
- ialabel - Labeling of connected components