8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SLIC Superpixel segmentation in scikit image

Posted at

To calculate SLIC superpixels in python, we have two options:

I found that these provided completely different segmentation unless enforce_connectivity=True in skimage.segmentation.slic. Here I show a brief example describing how different they are, which we could not see at http://scikit-image.org/docs/dev/auto_examples/plot_segmentations.html

example.py

from skimage.segmentation import slic, mark_boundaries
from skimage.data import lena
import slic as slic_wrap # code available at https://github.com/amueller/slic-python
import matplotlib.pyplot as plt

img = lena()

plt.subplot(1,3,1)
plt.imshow(mark_boundaries(img, slic_wrap.slic_n(img, 40, 10)))
title('Original version')
plt.subplot(1,3,2)
plt.imshow(mark_boundaries(img, slic(img, 40, 10, sigma=1, enforce_connectivity=False)))
title('skimage version\n enforce_connectivity=False', size=9)
plt.subplot(1,3,3)
plt.imshow(mark_boundaries(img, slic(img, 40, 10, sigma=1, enforce_connectivity=True)))
title('skimage version\n  enforce_connectivity=True', size=9)

Here I tried to tune the parameter sigma in skimage version to obtain a similar output to the original version. Obviously, enforce_connectivity option is essential to avoid color-sensitive segments.

Screen Shot 2014-07-08 at 9.56.51.png

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?