diff --git a/doc/examples/plot_rag_meancolor.py b/doc/examples/plot_rag_meancolor.py index aebfe6fc..1f19dd5e 100644 --- a/doc/examples/plot_rag_meancolor.py +++ b/doc/examples/plot_rag_meancolor.py @@ -3,47 +3,27 @@ RAG Thresholding ================ -This examples constructs a Region Adjacency Graph (RAG) and merges regions which are -similar in color. We construct a RAG and define edges as the difference in -mean color. We then join regions with similar mean color. +This examples constructs a Region Adjacency Graph (RAG) and merges regions +which are similar in color. We construct a RAG and define edges as the +difference in mean color. We then join regions with similar mean color. """ from skimage import graph from skimage import segmentation from skimage import data, io -import numpy as np from matplotlib import pyplot as plt +from skimage import color -def label_mask_img(img, label): - - out = np.zeros_like(img) - - red = img[:, :, 0] - green = img[:, :, 1] - blue = img[:, :, 2] - - for i in range(label.max()): - mask = label == i - - r = np.average(red[mask]) - g = np.average(green[mask]) - b = np.average(blue[mask]) - - # print r,g,b - out[mask] = r, g, b - - return out - img = data.coffee() labels1 = segmentation.slic(img, compactness=30, n_segments=400) -out1 = label_mask_img(img, labels1) +out1 = color.label2rgb(labels1, img, kind='avg') g = graph.rag_meancolor(img, labels1) labels2 = graph.threshold_cut(labels1, g, 30) -out2 = label_mask_img(img, labels2) +out2 = color.label2rgb(labels2, img, kind='avg') plt.figure() io.imshow(out1)