{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Shapes\n\nThis example shows how to draw several different shapes:\n\n- line\n- Bezier curve\n- polygon\n- disk\n- ellipse\n\nAnti-aliased drawing for:\n\n- line\n- circle\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import math\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom skimage.draw import (\n    line,\n    polygon,\n    disk,\n    circle_perimeter,\n    ellipse,\n    ellipse_perimeter,\n    bezier_curve,\n)\n\n\nfig, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(10, 6))\n\n\nimg = np.zeros((500, 500, 3), dtype=np.double)\n\n# draw line\nrr, cc = line(120, 123, 20, 400)\nimg[rr, cc, 0] = 255\n\n# fill polygon\npoly = np.array(\n    (\n        (300, 300),\n        (480, 320),\n        (380, 430),\n        (220, 590),\n        (300, 300),\n    )\n)\nrr, cc = polygon(poly[:, 0], poly[:, 1], img.shape)\nimg[rr, cc, 1] = 1\n\n# fill circle\nrr, cc = disk((200, 200), 100, shape=img.shape)\nimg[rr, cc, :] = (1, 1, 0)\n\n# fill ellipse\nrr, cc = ellipse(300, 300, 100, 200, img.shape)\nimg[rr, cc, 2] = 1\n\n# circle\nrr, cc = circle_perimeter(120, 400, 15)\nimg[rr, cc, :] = (1, 0, 0)\n\n# Bezier curve\nrr, cc = bezier_curve(70, 100, 10, 10, 150, 100, 1)\nimg[rr, cc, :] = (1, 0, 0)\n\n# ellipses\nrr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi / 4.0)\nimg[rr, cc, :] = (1, 0, 1)\nrr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=-math.pi / 4.0)\nimg[rr, cc, :] = (0, 0, 1)\nrr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi / 2.0)\nimg[rr, cc, :] = (1, 1, 1)\n\nax1.imshow(img)\nax1.set_title('No anti-aliasing')\nax1.axis('off')\n\n\nfrom skimage.draw import line_aa, circle_perimeter_aa\n\n\nimg = np.zeros((100, 100), dtype=np.double)\n\n# anti-aliased line\nrr, cc, val = line_aa(12, 12, 20, 50)\nimg[rr, cc] = val\n\n# anti-aliased circle\nrr, cc, val = circle_perimeter_aa(60, 40, 30)\nimg[rr, cc] = val\n\n\nax2.imshow(img, cmap=plt.cm.gray)\nax2.set_title('Anti-aliasing')\nax2.axis('off')\n\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
}