<jupyter_start><jupyter_text>mmdrulerDetect defects in a ruler.  DescriptionThe input image is a gray-scale image of a ruler, that has a number touching a tick mark. This number and mark are detected based on morphological and connected filtering.<jupyter_code>import numpy as np
from PIL import Image
import ia870 as ia
import matplotlib.pyplot as plt
print(ia.__version__)<jupyter_output>ia870 Python Morphology Toolbox version 0.8 25th Aug 2014 - in progress - migrating to Python 3<jupyter_text>ReadingThe gray-scale image of the ruler is read.<jupyter_code>a_pil = Image.open('data/mm3.tif').convert('L')
a = np.array (a_pil)

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('a')
axes.imshow(a, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>SegmentationThe close top-hat operator followed by a thresholding is applied.<jupyter_code>b = ia.iathreshad(ia.iacloseth(a,ia.iasebox(5)),40);

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('b')
axes.imshow(b, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Size filteringThe vertical lines longer than 50 pixels are detected.<jupyter_code>c = ia.iaopen(b,ia.iaseline(50,90))

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('c')
axes.imshow(c, cmap = 'gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Ruler tick marks filteringIt closes ruler tick marks gaps.<jupyter_code>d =ia.iaclose(c,ia.iaseline(15))

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('d')
axes.imshow(d, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Ruler tick marks connectionIt detects all objects connected to the ruler tick markers.<jupyter_code>e = ia.iainfrec(d,b)

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('e')
axes.imshow(e, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Ruler tick mark vertical connectionIt detects all objects vertically connected to the ruler tick mark. Note that the 3x1 rectangle is used as structuring element in the vertical reconstruction.<jupyter_code>f = ia.iainfrec(d,b,ia.iaseline(3,90));

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('f')
axes.imshow(f, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Non ruler tick mark vertical connectionThe residues obtained from the previous image.<jupyter_code>g = ia.iasubm(e,f)

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('g')
axes.imshow(g, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Ruler tick marks detectionIt uses an opening by an elementary cross structuring element to eliminate the artifacts.<jupyter_code>h = ia.iaopen(g)

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('h')
axes.imshow(h, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Objects detectionIt detects the objects connected to ruler tick marks. A reconstruction from the ruler marks detected is applied.<jupyter_code>i = ia.iainfrec(h, b)

(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('i')
axes.imshow(i, cmap='gray')
axes.axis('off')<jupyter_output><empty_output><jupyter_text>Final presentationOverlay the detected defect over the original image<jupyter_code>(fig, axes) = plt.subplots(nrows=1, ncols=1,figsize=(10, 5))
axes.set_title('a')
axes.imshow(ia.iagshow(a, i).transpose (1, 2, 0))
axes.axis('off')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14357401728463898, 'fraction_numerical': 0.023696682464454975, 'mean_word_length': 7.7299270072992705, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '102986', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1349, 'n_words': 297, 'path': 'druler.ipynb', 'repo_name': 'robertoalotufo/ia870p3', 'size': '3587'}