ENH Polish examples.

This commit is contained in:
Andreas Mueller
2012-08-03 11:37:10 +01:00
parent 07fb8d0c03
commit 80b439bb4a
2 changed files with 44 additions and 6 deletions
+19 -1
View File
@@ -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)))
+25 -5
View File
@@ -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)))