{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Contour finding\n\nWe use a marching squares method to find constant valued contours in an image.\nIn ``skimage.measure.find_contours``, array values are linearly interpolated\nto provide better precision of the output contours. Contours which intersect\nthe image edge are open; all others are closed.\n\nThe [marching squares algorithm](http://users.polytech.unice.fr/~lingrand/MarchingCubes/algo.html)_ is a\nspecial case of the marching cubes algorithm (Lorensen, William and Harvey\nE. Cline. Marching Cubes: A High Resolution 3D Surface Construction Algorithm.\nComputer Graphics SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170).\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\n\nfrom skimage import measure\n\n\n# Construct some test data\nx, y = np.ogrid[-np.pi : np.pi : 100j, -np.pi : np.pi : 100j]\nr = np.sin(np.exp(np.sin(x) ** 3 + np.cos(y) ** 2))\n\n# Find contours at a constant value of 0.8\ncontours = measure.find_contours(r, 0.8)\n\n# Display the image and plot all contours found\nfig, ax = plt.subplots()\nax.imshow(r, cmap=plt.cm.gray)\n\nfor contour in contours:\n    ax.plot(contour[:, 1], contour[:, 0], linewidth=2)\n\nax.axis('image')\nax.set_xticks([])\nax.set_yticks([])\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
}