Example jupyter notebook applications¶
Markdown formating¶
With markdown, you can easily format your text.
Unordered lists¶
- first item
- second item
- third item
Ordered lists¶
- First item
- Second item
- Third item
Tables¶
Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species | |
---|---|---|---|---|---|
130 | 7.2 | 3.0 | 5.8 | 1.6 | virginica |
27 | 5.0 | 3.4 | 1.6 | 0.4 | setosa |
63 | 6.0 | 2.2 | 4.0 | 1.0 | versicolor |
84 | 6.0 | 2.7 | 5.1 | 1.6 | versicolor |
114 | 5.7 | 2.5 | 5.0 | 2.0 | virginica |
40 | 5.1 | 3.4 | 1.5 | 0.2 | setosa |
50 | 5.0 | 3.3 | 1.4 | 0.2 | setosa |
45 | 5.1 | 3.8 | 1.9 | 0.4 | setosa |
28 | 5.2 | 3.5 | 1.5 | 0.2 | setosa |
146 | 6.7 | 3.0 | 5.2 | 2.3 | virginica |
48 | 4.6 | 3.2 | 1.4 | 0.2 | setosa |
6 | 5.4 | 3.9 | 1.7 | 0.4 | setosa |
92 | 6.1 | 3.0 | 4.6 | 1.4 | versicolor |
29 | 5.2 | 3.4 | 1.4 | 0.2 | setosa |
11 | 5.4 | 3.7 | 1.5 | 0.2 | setosa |
Add medias¶
Like images
Or GIFS
Execute code¶
In [1]:
# IMage segmentation example from scikit image
from skimage import data, io, segmentation, color
from skimage.future import graph
import numpy as np
%matplotlib inline
def _weight_mean_color(graph, src, dst, n):
"""Callback to handle merging nodes by recomputing mean color.
The method expects that the mean color of `dst` is already computed.
Parameters
----------
graph : RAG
The graph under consideration.
src, dst : int
The vertices in `graph` to be merged.
n : int
A neighbor of `src` or `dst` or both.
Returns
-------
data : dict
A dictionary with the `"weight"` attribute set as the absolute
difference of the mean color between node `dst` and `n`.
"""
diff = graph.node[dst]['mean color'] - graph.node[n]['mean color']
diff = np.linalg.norm(diff)
return {'weight': diff}
def merge_mean_color(graph, src, dst):
"""Callback called before merging two nodes of a mean color distance graph.
This method computes the mean color of `dst`.
Parameters
----------
graph : RAG
The graph under consideration.
src, dst : int
The vertices in `graph` to be merged.
"""
graph.node[dst]['total color'] += graph.node[src]['total color']
graph.node[dst]['pixel count'] += graph.node[src]['pixel count']
graph.node[dst]['mean color'] = (graph.node[dst]['total color'] /
graph.node[dst]['pixel count'])
# IMport test image
img = data.coffee()
# Visualize image
io.imshow(img)
io.show()
In [2]:
labels = segmentation.slic(img, compactness=30, n_segments=400)
g = graph.rag_mean_color(img, labels)
labels2 = graph.merge_hierarchical(labels, g, thresh=35, rag_copy=False,
in_place_merge=True,
merge_func=merge_mean_color,
weight_func=_weight_mean_color)
g2 = graph.rag_mean_color(img, labels2)
out = color.label2rgb(labels2, img, kind='avg')
out = segmentation.mark_boundaries(out, labels2, (0, 0, 0))
io.imshow(out)
io.show()