ENH felzenszwalb for color images

This commit is contained in:
Andreas Mueller
2012-08-03 11:37:10 +01:00
parent 7a5e7e49ea
commit 07fb8d0c03
4 changed files with 114 additions and 14 deletions
+19 -5
View File
@@ -3,11 +3,25 @@ import numpy as np
from skimage.data import lena
from skimage.segmentation import felzenszwalb_segmentation
from skimage.util import img_as_float
img = lena()
segments = felzenszwalb_segmentation(img, k=1000)
plt.imshow(img)
plt.figure()
plt.imshow(segments)
img = img_as_float(lena())
segments = felzenszwalb_segmentation(img, scale=1)
segments = np.unique(segments, return_inverse=True)[1].reshape(img.shape[:2])
plt.subplot(131, title="original")
plt.imshow(img, interpolation='nearest')
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.subplot(133, title="mean color")
colors = [np.bincount(segments.ravel(), img[:, :, c].ravel()) for c in
xrange(img.shape[2])]
counts = np.bincount(segments.ravel())
colors = np.vstack(colors) / counts
plt.imshow(colors.T[segments], interpolation='nearest')
plt.show()
print("num segments: %d" % len(np.unique(segments)))