{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Generate footprints (structuring elements)\n\nThis example shows how to use functions in :py:mod:`skimage.morphology`\nto generate footprints (structuring elements) for use in morphology operations.\nThe title of each plot indicates the call of the function.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom skimage.morphology import (\n    footprint_rectangle,\n    diamond,\n    disk,\n    octahedron,\n    ball,\n    octagon,\n    star,\n)\n\n# Generate 2D and 3D structuring elements.\nstruc_2d = {\n    \"square 15x15\": footprint_rectangle((15, 15)),\n    \"rectangle 15x10\": footprint_rectangle((15, 10)),\n    \"diamond(7)\": diamond(7),\n    \"disk(7)\": disk(7),\n    \"octagon(7, 4)\": octagon(7, 4),\n    \"star(5)\": star(5),\n}\n\nstruc_3d = {\n    \"cube 11x11x11\": footprint_rectangle((11, 11, 11)),\n    \"octahedron(5)\": octahedron(5),\n    \"ball(5)\": ball(5),\n}\n\n# Visualize the elements.\nfig = plt.figure(figsize=(8, 8))\n\nidx = 1\nfor title, struc in struc_2d.items():\n    ax = fig.add_subplot(3, 3, idx)\n    ax.imshow(struc, cmap=\"Paired\", vmin=0, vmax=12)\n    for i in range(struc.shape[0]):\n        for j in range(struc.shape[1]):\n            ax.text(j, i, struc[i, j], ha=\"center\", va=\"center\", color=\"w\")\n    ax.set_axis_off()\n    ax.set_title(title)\n    idx += 1\n\nfor title, struc in struc_3d.items():\n    ax = fig.add_subplot(3, 3, idx, projection=Axes3D.name)\n    ax.voxels(struc)\n    ax.set_title(title)\n    idx += 1\n\nfig.tight_layout()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}