.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/numpy_operations/plot_structuring_elements.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_numpy_operations_plot_structuring_elements.py: ========================================== Generate footprints (structuring elements) ========================================== This example shows how to use functions in :py:mod:`skimage.morphology` to generate footprints (structuring elements) for use in morphology operations. The title of each plot indicates the call of the function. .. GENERATED FROM PYTHON SOURCE LINES 11-61 .. image-sg:: /auto_examples/numpy_operations/images/sphx_glr_plot_structuring_elements_001.png :alt: square(15), rectangle(15, 10), diamond(7), disk(7), octagon(7, 4), star(5), cube(11), octahedron(5), ball(5) :srcset: /auto_examples/numpy_operations/images/sphx_glr_plot_structuring_elements_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from skimage.morphology import ( square, rectangle, diamond, disk, cube, octahedron, ball, octagon, star, ) # Generate 2D and 3D structuring elements. struc_2d = { "square(15)": square(15), "rectangle(15, 10)": rectangle(15, 10), "diamond(7)": diamond(7), "disk(7)": disk(7), "octagon(7, 4)": octagon(7, 4), "star(5)": star(5), } struc_3d = {"cube(11)": cube(11), "octahedron(5)": octahedron(5), "ball(5)": ball(5)} # Visualize the elements. fig = plt.figure(figsize=(8, 8)) idx = 1 for title, struc in struc_2d.items(): ax = fig.add_subplot(3, 3, idx) ax.imshow(struc, cmap="Paired", vmin=0, vmax=12) for i in range(struc.shape[0]): for j in range(struc.shape[1]): ax.text(j, i, struc[i, j], ha="center", va="center", color="w") ax.set_axis_off() ax.set_title(title) idx += 1 for title, struc in struc_3d.items(): ax = fig.add_subplot(3, 3, idx, projection=Axes3D.name) ax.voxels(struc) ax.set_title(title) idx += 1 fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.130 seconds) .. _sphx_glr_download_auto_examples_numpy_operations_plot_structuring_elements.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.24.0?filepath=notebooks/auto_examples/numpy_operations/plot_structuring_elements.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_structuring_elements.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_structuring_elements.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_structuring_elements.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_