mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
ENH Polish examples.
This commit is contained in:
@@ -1,3 +1,21 @@
|
||||
"""
|
||||
=================================================
|
||||
Felzenszwalb's efficient graph based segmentation
|
||||
=================================================
|
||||
|
||||
This fast 2d image segmentation algorithm, proposed in [1]_ is popular in the
|
||||
computer vision community. It is often used to extract "superpixels", small
|
||||
homogeneous image regions, which build the basis for further processing.
|
||||
|
||||
The algorithm has a single ``scale`` parameter that influences the segment
|
||||
size. The actual size and number of segments can vary greatly, depending on
|
||||
local contrast.
|
||||
|
||||
.. [1] Efficient graph-based image segmentation, Felzenszwalb, P.F. and
|
||||
Huttenlocher, D.P. International Journal of Computer Vision, 2004
|
||||
"""
|
||||
print __doc__
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
@@ -23,5 +41,5 @@ colors = [np.bincount(segments.ravel(), img[:, :, c].ravel()) for c in
|
||||
counts = np.bincount(segments.ravel())
|
||||
colors = np.vstack(colors) / counts
|
||||
plt.imshow(colors.T[segments], interpolation='nearest')
|
||||
print("number of segments: %d" % len(np.unique(segments)))
|
||||
plt.show()
|
||||
print("num segments: %d" % len(np.unique(segments)))
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
"""
|
||||
=============================
|
||||
Quickshift image segmentation
|
||||
=============================
|
||||
|
||||
Quickshift is a relatively recent 2d image segmentation algorithm, based on an
|
||||
approximation of kernelized mean-shift. Therefore it belongs to the family
|
||||
of local mode-seeking algorithms and is applied to the color+coordinate space,
|
||||
see [1]_ It is often used to extract "superpixels", small homogeneous image
|
||||
regions, which build the basis for further processing.
|
||||
|
||||
One of the benefits of quickshift is that it actually computes a
|
||||
hierarchical segmentation on multiple scales simultaneously.
|
||||
|
||||
Quickshift has two parameters, one controlling the scale of the local
|
||||
density approximation, the other selecting a level in the hierarchical
|
||||
segmentation that is produced.
|
||||
|
||||
.. [1] Quick shift and kernel methods for mode seeking, Vedaldi, A. and Soatto, S.
|
||||
European Conference on Computer Vision, 2008
|
||||
"""
|
||||
print __doc__
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
@@ -5,11 +28,8 @@ from skimage.data import lena
|
||||
from skimage.segmentation import quickshift
|
||||
from skimage.util import img_as_float
|
||||
|
||||
from IPython.core.debugger import Tracer
|
||||
tracer = Tracer()
|
||||
|
||||
|
||||
img = img_as_float(lena())
|
||||
img = img_as_float(lena())[::2, ::2, :].copy("C")
|
||||
segments = quickshift(img, sigma=5, tau=20)
|
||||
segments = np.unique(segments, return_inverse=True)[1].reshape(img.shape[:2])
|
||||
|
||||
@@ -27,5 +47,5 @@ colors = [np.bincount(segments.ravel(), img[:, :, c].ravel()) for c in
|
||||
counts = np.bincount(segments.ravel())
|
||||
colors = np.vstack(colors) / counts
|
||||
plt.imshow(colors.T[segments], interpolation='nearest')
|
||||
print("number of segments: %d" % len(np.unique(segments)))
|
||||
plt.show()
|
||||
print("num segments: %d" % len(np.unique(segments)))
|
||||
|
||||
Reference in New Issue
Block a user