DOC document and export felzenszwalb_segmentation_grey, prettify plots for the web.

This commit is contained in:
Andreas Mueller
2012-06-17 23:17:29 +02:00
parent 9a8cb483c4
commit 4d10749a0e
4 changed files with 30 additions and 4 deletions
@@ -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()
+8 -1
View File
@@ -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()
+3 -1
View File
@@ -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]
+10
View File
@@ -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]