Visit the wiki pages to find some additional documentation and instructions on how view an interactive verson of these notebooks using binder.

In [1]:
import math
import numpy as np
import matplotlib.pyplot as plt


from skimage import io
from skimage.segmentation import slic
from skimage.segmentation import mark_boundaries

%matplotlib inline

Partition the image into superpixels

In [2]:
image = io.imread("../images/tma.jpg")
rows, cols, depth = image.shape
print(rows)
print(cols)
print(depth)
600
600
3
In [3]:
fig, ax = plt.subplots(figsize=(8, 8))
plt.imshow(image)
Out[3]:
<matplotlib.image.AxesImage at 0x7fa75e85fcd0>
In [4]:
segments_slic_0 = slic(image, n_segments=200, compactness=2, sigma=.5)
segments_slic_1 = slic(image, n_segments=200, compactness=8, sigma=.5)
segments_slic_2 = slic(image, n_segments=200, compactness=200, sigma=.5)
print(np.amax(segments_slic_0))
print(np.amax(segments_slic_1))
print(np.amax(segments_slic_2))
22
101
195

Notice what happens when the compactness of the superpixels is slow (left image).

In [5]:
fig, ax = plt.subplots(figsize=(16, 16))
plt.subplot(1,3,1).set_axis_off()
plt.imshow(mark_boundaries(image, segments_slic_0))
plt.subplot(1,3,2).set_axis_off()
plt.imshow(mark_boundaries(image, segments_slic_1))
plt.subplot(1,3,3).set_axis_off()
plt.imshow(mark_boundaries(image, segments_slic_2))
plt.show()
In [ ]:
 
In [ ]: