mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-28 19:01:23 +08:00
55f5103dd8
Modified travis_script.sh to account for the new structure of the gallery Added README.txt files in directories of gallery examples Fixed references to gallery images in user guide pages Fixed broken links
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""
|
|
===============
|
|
Contour finding
|
|
===============
|
|
|
|
``skimage.measure.find_contours`` uses a marching squares method to find
|
|
constant valued contours in an image. 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
|
|
<http://www.essi.fr/~lingrand/MarchingCubes/algo.html>`__ 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).
|
|
|
|
"""
|
|
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, interpolation='nearest', cmap=plt.cm.gray)
|
|
|
|
for n, contour in enumerate(contours):
|
|
ax.plot(contour[:, 1], contour[:, 0], linewidth=2)
|
|
|
|
ax.axis('image')
|
|
ax.set_xticks([])
|
|
ax.set_yticks([])
|
|
plt.show()
|