.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/edges/plot_contours.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_edges_plot_contours.py: =============== Contour finding =============== We use a marching squares method to find constant valued contours in an image. In ``skimage.measure.find_contours``, array values are linearly interpolated to provide better precision of the output contours. Contours which intersect the image edge are open; all others are closed. The `marching squares algorithm `__ is a special case of the marching cubes algorithm (Lorensen, William and Harvey E. Cline. Marching Cubes: A High Resolution 3D Surface Construction Algorithm. Computer Graphics SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170). .. GENERATED FROM PYTHON SOURCE LINES 18-43 .. image-sg:: /auto_examples/edges/images/sphx_glr_plot_contours_001.png :alt: plot contours :srcset: /auto_examples/edges/images/sphx_glr_plot_contours_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from skimage import measure # Construct some test data x, y = np.ogrid[-np.pi : np.pi : 100j, -np.pi : np.pi : 100j] r = np.sin(np.exp(np.sin(x) ** 3 + np.cos(y) ** 2)) # Find contours at a constant value of 0.8 contours = measure.find_contours(r, 0.8) # Display the image and plot all contours found fig, ax = plt.subplots() ax.imshow(r, cmap=plt.cm.gray) for contour in contours: ax.plot(contour[:, 1], contour[:, 0], linewidth=2) ax.axis('image') ax.set_xticks([]) ax.set_yticks([]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.072 seconds) .. _sphx_glr_download_auto_examples_edges_plot_contours.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/edges/plot_contours.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_contours.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_contours.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_contours.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_