diff --git a/doc/examples/plot_felzenszwalb_segmentation.py b/doc/examples/plot_felzenszwalb_segmentation.py index 0b8a2e8c..27581fb1 100644 --- a/doc/examples/plot_felzenszwalb_segmentation.py +++ b/doc/examples/plot_felzenszwalb_segmentation.py @@ -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))) diff --git a/doc/examples/plot_quickshift.py b/doc/examples/plot_quickshift.py index b21c56e8..29f44899 100644 --- a/doc/examples/plot_quickshift.py +++ b/doc/examples/plot_quickshift.py @@ -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)))