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, segmentation, color
from skimage.future import graph

%matplotlib inline
In [2]:
image = io.imread("../images/head-ct.jpg")
rows, cols, depth = image.shape
print(rows)
print(cols)
print(depth)
720
960
3
In [3]:
fig, ax = plt.subplots(figsize=(8, 8))
plt.imshow(image)
Out[3]:
<matplotlib.image.AxesImage at 0x7ff939e87a50>

Partion the image into superpixels

In [8]:
segments_slic = segmentation.slic(image, n_segments=1200, compactness=30, sigma=.5)
print(np.amax(segments_slic))
1166
In [9]:
fig, ax = plt.subplots(figsize=(8, 8))
plt.imshow(segmentation.mark_boundaries(image, segments_slic))
plt.show()

Now compute the normalised cut on the superpixels

In [10]:
g = graph.rag_mean_color(image, segments_slic, mode='similarity')
labels = graph.cut_normalized(segments_slic, g)
output = color.label2rgb(labels, image, kind='avg')
In [11]:
fig, ax = plt.subplots(figsize=(8, 8))
plt.imshow(output)
plt.show()
In [ ]: