<jupyter_start><jupyter_text>mmdgearDetect the teeth of a gear  DescriptionThe 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.<jupyter_code>import numpy as np
from PIL import Image
import ia870 as ia
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>ReadingThe binary image of a gear is read.<jupyter_code>a_pil = Image.open('../data/gear.tif').convert('L')
a = np.array (a_pil)
(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(5, 5))
axes.set_title('a')
axes.imshow(a, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Opening and subtractionOpening 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));<jupyter_code>b = ia.iaopen(a,ia.iasedisk(20));
c = ia.iasubm(a,b);

(fig, axes) = plt.subplots(nrows=1, ncols=2,figsize=(10, 5))
axes[0].set_title('b')
axes[0].imshow(b, cmap='gray')
axes[0].axis('off')
axes[1].set_title('c')
axes[1].imshow(c, cmap='gray')
axes[1].axis('off')<jupyter_output><empty_output><jupyter_text>FilteringA connected filtering is applied to remove small artifacts present in the image.<jupyter_code>d = ia.ialabel(c);
nteeth=ia.iastats(d,'max')
print(nteeth)

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(5, 5))
axes.set_title('c')
axes.imshow(ia.iaglblshow(d, 'border').transpose(1, 2, 0))
axes.axis('off')<jupyter_output>24
{'fraction_non_alphanumeric': 0.15057915057915058, 'fraction_numerical': 0.021235521235521235, 'mean_word_length': 6.853535353535354, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '50349', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 636, 'n_tokens_neox': 600, 'n_words': 144, 'path': 'notebooks/dgear.ipynb', 'repo_name': 'rdenadai/ia870p3', 'size': '1554'}