Improved drawing in plot_rag_draw.py example (#1872)

Improved drawing in draw_rag example; changed draw_rag to show_rag, made it return ScalarMappable to draw colorbars; added magma colormap
This commit is contained in:
Vighnesh Birodkar
2016-04-24 09:28:24 +03:00
committed by Egor Panfilov
parent e6fd683d74
commit a406e270b1
6 changed files with 347 additions and 88 deletions
+12 -20
View File
@@ -8,33 +8,25 @@ the `rag_draw` method.
"""
from skimage import data, segmentation
from skimage.future import graph
from skimage.util.colormap import viridis
from matplotlib import pyplot as plt, colors
from matplotlib import pyplot as plt
img = data.coffee()
labels = segmentation.slic(img, compactness=30, n_segments=400)
g = graph.rag_mean_color(img, labels)
out = graph.draw_rag(labels, g, img)
plt.figure()
plt.title("RAG with all edges shown in green.")
plt.imshow(out)
# The color palette used was taken from
# http://www.colorcombos.com/color-schemes/2/ColorCombo2.html
cmap = colors.ListedColormap(['#6599FF', '#ff9900'])
out = graph.draw_rag(labels, g, img, node_color="#ffde00", colormap=cmap,
thresh=30, desaturate=True)
plt.figure()
plt.title("RAG with edge weights less than 30, color "
"mapped between blue and orange.")
plt.imshow(out)
fig, ax = plt.subplots()
ax.set_title('RAG drawn with default settings')
lc = graph.show_rag(labels, g, img, ax=ax)
# fraction specifies the fraction of the area of the plot that will be used to
# draw the colorbar
plt.colorbar(lc, fraction=0.03)
plt.figure()
plt.title("All edges drawn with viridis colormap")
out = graph.draw_rag(labels, g, img, colormap=viridis,
desaturate=True)
fig, ax = plt.subplots()
ax.set_title('RAG drawn with grayscale image and viridis colormap')
lc = graph.show_rag(labels, g, img, img_cmap='gray', edge_cmap='viridis',
ax=ax)
plt.colorbar(lc, fraction=0.03)
plt.imshow(out)
plt.show()