mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-01 12:50:48 +08:00
added boundary rag construction
This commit is contained in:
committed by
Vighnesh Birodkar
parent
8f2839e1b3
commit
1769cdddcf
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
==========================
|
||||
Region Boundary based RAGs
|
||||
==========================
|
||||
|
||||
This example demonstrates construction of region boundary based RAGs with the
|
||||
`rag_boundary` function.
|
||||
"""
|
||||
from skimage.future import graph
|
||||
from skimage import data, segmentation, color, filters, io
|
||||
from matplotlib import pyplot as plt, colors
|
||||
|
||||
img = data.coffee()
|
||||
gimg = color.rgb2gray(img)
|
||||
|
||||
labels = segmentation.slic(img, compactness=30, n_segments=400)
|
||||
edges = filters.sobel(gimg)
|
||||
edges_rgb = color.gray2rgb(edges)
|
||||
|
||||
mimg = segmentation.mark_boundaries(img, labels, (0,0,0))
|
||||
|
||||
g = graph.rag_boundary(labels, edges)
|
||||
|
||||
cmap = colors.ListedColormap(['#0000ff', '#ff0000'])
|
||||
out = graph.draw_rag(labels, g, edges_rgb, node_color="#ffff00", colormap=cmap)
|
||||
|
||||
io.imshow(out)
|
||||
io.show()
|
||||
Reference in New Issue
Block a user