diff --git a/doc/examples/plot_felzenszwalb_segmentation.py b/doc/examples/plot_felzenszwalb_segmentation.py index 27581fb1..3d06dd2a 100644 --- a/doc/examples/plot_felzenszwalb_segmentation.py +++ b/doc/examples/plot_felzenszwalb_segmentation.py @@ -27,13 +27,17 @@ img = img_as_float(lena()) segments = felzenszwalb_segmentation(img, scale=1) segments = np.unique(segments, return_inverse=True)[1].reshape(img.shape[:2]) +print("number of segments: %d" % len(np.unique(segments))) + plt.subplot(131, title="original") plt.imshow(img, interpolation='nearest') +plt.axis("off") -plt.subplot(132, title="superpixels") +plt.subplot(132, title="segmentation") # shuffle the labels for better visualization permuted_labels = np.random.permutation(segments.max() + 1) plt.imshow(permuted_labels[segments], interpolation='nearest') +plt.axis("off") plt.subplot(133, title="mean color") colors = [np.bincount(segments.ravel(), img[:, :, c].ravel()) for c in @@ -41,5 +45,8 @@ 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.axis("off") + +plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, + bottom=0.02, left=0.02, right=0.98) plt.show() diff --git a/doc/examples/plot_quickshift.py b/doc/examples/plot_quickshift.py index 29f44899..d807ae14 100644 --- a/doc/examples/plot_quickshift.py +++ b/doc/examples/plot_quickshift.py @@ -33,13 +33,17 @@ 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]) +print("number of segments: %d" % len(np.unique(segments))) + plt.subplot(131, title="original") plt.imshow(img, interpolation='nearest') +plt.axis("off") plt.subplot(132, title="superpixels") # shuffle the labels for better visualization permuted_labels = np.random.permutation(segments.max() + 1) plt.imshow(permuted_labels[segments], interpolation='nearest') +plt.axis("off") plt.subplot(133, title="mean color") colors = [np.bincount(segments.ravel(), img[:, :, c].ravel()) for c in @@ -47,5 +51,8 @@ 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.axis("off") + +plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, + bottom=0.02, left=0.02, right=0.98) plt.show() diff --git a/skimage/segmentation/__init__.py b/skimage/segmentation/__init__.py index 8fa8dfb8..36595240 100644 --- a/skimage/segmentation/__init__.py +++ b/skimage/segmentation/__init__.py @@ -1,5 +1,7 @@ from .random_walker_segmentation import random_walker from .felzenszwalb import felzenszwalb_segmentation +from .felzenszwalb import felzenszwalb_segmentation_grey from .quickshift import quickshift -__all__ = [random_walker, quickshift, felzenszwalb_segmentation] +__all__ = [random_walker, quickshift, felzenszwalb_segmentation, + felzenszwalb_segmentation_grey] diff --git a/skimage/segmentation/_felzenszwalb.pyx b/skimage/segmentation/_felzenszwalb.pyx index cbdaac89..5a6db993 100644 --- a/skimage/segmentation/_felzenszwalb.pyx +++ b/skimage/segmentation/_felzenszwalb.pyx @@ -54,6 +54,16 @@ cdef join_trees(np.int_t *forest, np.int_t n, np.int_t m): def felzenszwalb_segmentation_grey(image, scale=200, sigma=0.8): """Computes Felsenszwalb's efficient graph based segmentation for a single channel. + Produces an oversegmentation of a 2d image using a fast, minimum spanning + tree based clustering on the image grid. The parameter ``scale`` sets an + observation level. Higher scale means less and larger segments. ``sigma`` + is the diameter of a Gaussian kernel, used for smoothing the image prior to + segmentation. + + The number of produced segments as well as their size can only be + controlled indirectly through ``scale``. Segment size within an image can + vary greatly depending on local contrast. + Parameters ---------- image: ndarray, [width, height]