.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/scribo/example_line_detector.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_scribo_example_line_detector.py: Line detection example ====================== This example shows how to use the line detector with Pylena. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: Python import matplotlib.pyplot as plt from skimage.data import text import pylena as pln import numpy as np from typing import List .. GENERATED FROM PYTHON SOURCE LINES 18-19 Then, we read the image. .. GENERATED FROM PYTHON SOURCE LINES 19-27 .. code-block:: Python img = text() plt.imshow(img, cmap="gray") plt.xticks([]) plt.yticks([]) plt.show() .. image-sg:: /examples/scribo/images/sphx_glr_example_line_detector_001.png :alt: example line detector :srcset: /examples/scribo/images/sphx_glr_example_line_detector_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 28-29 Then, we use the line detector. .. GENERATED FROM PYTHON SOURCE LINES 29-44 .. code-block:: Python img_label: np.ndarray superpositions: List[pln.scribo.LSuperposition] lines: List[pln.scribo.VSegment] img_label, superpositions, lines = pln.scribo.line_detector( img, "full", verbose=True, min_len=100, blumi=110, llumi=110, discontinuity_relative=5, ) .. rst-class:: sphx-glr-script-out .. code-block:: none min_len = 100 params = .. GENERATED FROM PYTHON SOURCE LINES 45-46 Finally, we display the results of the line detector. .. GENERATED FROM PYTHON SOURCE LINES 46-56 .. code-block:: Python plt.imshow(img, cmap="gray") for line in lines: print(line) plt.plot([line.x0, line.x1], [line.y0, line.y1], color="red") plt.xticks([]) plt.yticks([]) plt.show() .. image-sg:: /examples/scribo/images/sphx_glr_example_line_detector_002.png :alt: example line detector :srcset: /examples/scribo/images/sphx_glr_example_line_detector_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 2: (0, 86) -- (124, 154) 3: (5, 137) -- (191, 86) 4: (0, 12) -- (265, 132) 5: (310, 70) -- (427, 50) 6: (341, 31) -- (447, 67) 7: (110, 0) -- (446, 131) .. GENERATED FROM PYTHON SOURCE LINES 57-58 We can also display the pixel information. .. GENERATED FROM PYTHON SOURCE LINES 58-81 .. code-block:: Python img_rgb = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8) img_rgb[:, :, 0] = img img_rgb[:, :, 1] = img img_rgb[:, :, 2] = img max_label = np.max(img_label) np.random.seed(0) color = np.random.randint(low=0, high=255, size=(max_label - 2, 3)) for i in range(2, max_label): img_rgb[img_label == i, 0] = color[i - 2, 0] img_rgb[img_label == i, 1] = color[i - 2, 1] img_rgb[img_label == i, 2] = color[i - 2, 2] plt.imshow(img_rgb) plt.xticks([]) plt.yticks([]) plt.show() .. image-sg:: /examples/scribo/images/sphx_glr_example_line_detector_003.png :alt: example line detector :srcset: /examples/scribo/images/sphx_glr_example_line_detector_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 82-83 We can also display the include the superposition information. .. GENERATED FROM PYTHON SOURCE LINES 83-98 .. code-block:: Python img_rgb_with_superposition = img_rgb.copy() for superposition in superpositions: print(superposition) img_rgb_with_superposition[superposition.y, superposition.x, 0] = 255 img_rgb_with_superposition[superposition.y, superposition.x, 1] = 0 img_rgb_with_superposition[superposition.y, superposition.x, 2] = 0 plt.imshow(img_rgb_with_superposition) plt.xticks([]) plt.yticks([]) plt.show() .. image-sg:: /examples/scribo/images/sphx_glr_example_line_detector_004.png :alt: example line detector :srcset: /examples/scribo/images/sphx_glr_example_line_detector_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 2: (56, 117) 3: (56, 117) 2: (56, 118) 3: (56, 118) 2: (56, 119) 3: (56, 119) 2: (56, 120) 3: (56, 120) 2: (56, 121) 3: (56, 121) 2: (56, 122) 3: (56, 122) 2: (57, 117) 3: (57, 117) 2: (57, 118) 3: (57, 118) 2: (57, 119) 3: (57, 119) 2: (57, 120) 3: (57, 120) 2: (57, 121) 3: (57, 121) 2: (57, 122) 3: (57, 122) 2: (58, 118) 3: (58, 118) 2: (58, 119) 3: (58, 119) 2: (58, 120) 3: (58, 120) 2: (58, 121) 3: (58, 121) 2: (59, 118) 3: (59, 118) 2: (59, 119) 3: (59, 119) 2: (59, 120) 3: (59, 120) 2: (59, 121) 3: (59, 121) 2: (60, 118) 3: (60, 118) 2: (60, 119) 3: (60, 119) 2: (60, 120) 3: (60, 120) 2: (60, 121) 3: (60, 121) 2: (61, 118) 3: (61, 118) 2: (61, 119) 3: (61, 119) 2: (61, 120) 3: (61, 120) 2: (61, 121) 3: (61, 121) 2: (62, 118) 3: (62, 118) 2: (62, 119) 3: (62, 119) 2: (62, 120) 3: (62, 120) 2: (62, 121) 3: (62, 121) 2: (62, 122) 3: (62, 122) 3: (165, 85) 4: (165, 85) 3: (165, 86) 4: (165, 86) 3: (165, 87) 4: (165, 87) 3: (166, 85) 4: (166, 85) 3: (166, 86) 4: (166, 86) 3: (166, 87) 4: (166, 87) 3: (166, 88) 4: (166, 88) 3: (167, 87) 4: (167, 87) 3: (167, 88) 4: (167, 88) 3: (168, 87) 4: (168, 87) 3: (168, 88) 4: (168, 88) 3: (169, 87) 4: (169, 87) 3: (169, 88) 4: (169, 88) 3: (170, 88) 4: (170, 88) 3: (170, 89) 4: (170, 89) 3: (171, 88) 4: (171, 88) 3: (171, 89) 4: (171, 89) 3: (172, 88) 4: (172, 88) 3: (172, 89) 4: (172, 89) 3: (172, 90) 4: (172, 90) 3: (173, 88) 4: (173, 88) 3: (173, 89) 4: (173, 89) 5: (399, 50) 6: (399, 50) 5: (399, 51) 6: (399, 51) 5: (399, 52) 6: (399, 52) 5: (399, 53) 6: (399, 53) 5: (400, 50) 6: (400, 50) 5: (400, 51) 6: (400, 51) 5: (400, 52) 6: (400, 52) 5: (400, 53) 6: (400, 53) 5: (401, 50) 6: (401, 50) 5: (401, 51) 6: (401, 51) 5: (401, 52) 6: (401, 52) 5: (401, 53) 6: (401, 53) 5: (402, 51) 6: (402, 51) 5: (402, 52) 6: (402, 52) 5: (402, 53) 6: (402, 53) 5: (403, 51) 6: (403, 51) 5: (403, 52) 6: (403, 52) 5: (403, 53) 6: (403, 53) 5: (404, 51) 6: (404, 51) 5: (404, 52) 6: (404, 52) 5: (404, 53) 6: (404, 53) 5: (405, 51) 6: (405, 51) 5: (405, 52) 6: (405, 52) 5: (405, 53) 6: (405, 53) 5: (406, 51) 6: (406, 51) 5: (406, 52) 6: (406, 52) 5: (406, 53) 6: (406, 53) 5: (407, 51) 6: (407, 51) 5: (407, 52) 6: (407, 52) 5: (407, 53) 6: (407, 53) 5: (408, 51) 6: (408, 51) 5: (408, 52) 6: (408, 52) 5: (408, 53) 6: (408, 53) 5: (409, 50) 6: (409, 50) 5: (409, 51) 6: (409, 51) 5: (409, 52) 6: (409, 52) 5: (398, 49) 6: (398, 49) 5: (398, 50) 6: (398, 50) 5: (398, 51) 6: (398, 51) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.211 seconds) .. _sphx_glr_download_examples_scribo_example_line_detector.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_line_detector.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_line_detector.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_line_detector.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_