future.graph
¶skimage.future.graph.cut_normalized (labels, rag) |
Perform Normalized Graph cut on the Region Adjacency Graph. |
skimage.future.graph.cut_threshold (labels, ...) |
Combine regions separated by weight less than threshold. |
skimage.future.graph.draw_rag (labels, rag, img) |
Draw a Region Adjacency Graph on an image. |
skimage.future.graph.merge_hierarchical (...) |
Perform hierarchical merging of a RAG. |
skimage.future.graph.ncut (labels, rag[, ...]) |
Perform Normalized Graph cut on the Region Adjacency Graph. |
skimage.future.graph.rag_boundary (labels, ...) |
Comouter RAG based on region boundaries |
skimage.future.graph.rag_mean_color (image, ...) |
Compute the Region Adjacency Graph using mean colors. |
skimage.future.graph.RAG ([label_image, ...]) |
The Region Adjacency Graph (RAG) of an image, subclasses |
skimage.future.graph.
cut_normalized
(labels, rag, thresh=0.001, num_cuts=10, in_place=True, max_edge=1.0)[source]¶Perform Normalized Graph cut on the Region Adjacency Graph.
Given an image’s labels and its similarity RAG, recursively perform a 2-way normalized cut on it. All nodes belonging to a subgraph that cannot be cut further are assigned a unique label in the output.
Parameters: | labels : ndarray
rag : RAG
thresh : float
num_cuts : int
in_place : bool
max_edge : float, optional
|
---|---|
Returns: | out : ndarray
|
References
[R223] | Shi, J.; Malik, J., “Normalized cuts and image segmentation”, Pattern Analysis and Machine Intelligence, IEEE Transactions on, vol. 22, no. 8, pp. 888-905, August 2000. |
Examples
>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img, compactness=30, n_segments=400)
>>> rag = graph.rag_mean_color(img, labels, mode='similarity')
>>> new_labels = graph.cut_normalized(labels, rag)
skimage.future.graph.
cut_threshold
(labels, rag, thresh, in_place=True)[source]¶Combine regions separated by weight less than threshold.
Given an image’s labels and its RAG, output new labels by combining regions whose nodes are separated by a weight less than the given threshold.
Parameters: | labels : ndarray
rag : RAG
thresh : float
in_place : bool
|
---|---|
Returns: | out : ndarray
|
References
[R224] | Alain Tremeau and Philippe Colantoni “Regions Adjacency Graph Applied To Color Image Segmentation” http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5274 |
Examples
>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img)
>>> rag = graph.rag_mean_color(img, labels)
>>> new_labels = graph.cut_threshold(labels, rag, 10)
skimage.future.graph.
draw_rag
(labels, rag, img, border_color=None, node_color='#ffff00', edge_color='#00ff00', colormap=None, thresh=inf, desaturate=False, in_place=True)[source]¶Draw a Region Adjacency Graph on an image.
Given a labelled image and its corresponding RAG, draw the nodes and edges of the RAG on the image with the specified colors. Nodes are marked by the centroids of the corresponding regions.
Parameters: | labels : ndarray, shape (M, N)
rag : RAG
img : ndarray, shape (M, N, 3)
border_color : colorspec, optional
node_color : colorspec, optional
edge_color : colorspec, optional
colormap : colormap, optional
thresh : float, optional
desaturate : bool, optional
in_place : bool, optional
|
---|---|
Returns: | out : ndarray, shape (M, N, 3)
|
Examples
>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.coffee()
>>> labels = segmentation.slic(img)
>>> g = graph.rag_mean_color(img, labels)
>>> out = graph.draw_rag(labels, g, img)
skimage.future.graph.
merge_hierarchical
(labels, rag, thresh, rag_copy, in_place_merge, merge_func, weight_func)[source]¶Perform hierarchical merging of a RAG.
Greedily merges the most similar pair of nodes until no edges lower than thresh remain.
Parameters: | labels : ndarray
rag : RAG
thresh : float
rag_copy : bool
in_place_merge : bool
merge_func : callable
weight_func : callable
|
---|---|
Returns: | out : ndarray
|
skimage.future.graph.
ncut
(labels, rag, thresh=0.001, num_cuts=10, in_place=True, max_edge=1.0)[source]¶Perform Normalized Graph cut on the Region Adjacency Graph.
Given an image’s labels and its similarity RAG, recursively perform a 2-way normalized cut on it. All nodes belonging to a subgraph that cannot be cut further are assigned a unique label in the output.
Parameters: | labels : ndarray
rag : RAG
thresh : float
num_cuts : int
in_place : bool
max_edge : float, optional
|
---|---|
Returns: | out : ndarray
|
References
[R225] | Shi, J.; Malik, J., “Normalized cuts and image segmentation”, Pattern Analysis and Machine Intelligence, IEEE Transactions on, vol. 22, no. 8, pp. 888-905, August 2000. |
Examples
>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img, compactness=30, n_segments=400)
>>> rag = graph.rag_mean_color(img, labels, mode='similarity')
>>> new_labels = graph.cut_normalized(labels, rag)
skimage.future.graph.
rag_boundary
(labels, edge_map, connectivity=2)[source]¶Comouter RAG based on region boundaries
Given an image’s initial segmentation and its edge map this method constructs the corresponding Region Adjacency Graph (RAG). Each node in the RAG represents a set of pixels within the image with the same label in labels. The weight between two adjacent regions is the average value in edge_map along their boundary.
Examples
>>> from skimage import data, segmentation, filters, color
>>> from skimage.future import graph
>>> img = data.chelsea()
>>> labels = segmentation.slic(img)
>>> edge_map = filters.sobel(color.rgb2gray(img))
>>> rag = graph.rag_boundary(labels, edge_map)
skimage.future.graph.
rag_mean_color
(image, labels, connectivity=2, mode='distance', sigma=255.0)[source]¶Compute the Region Adjacency Graph using mean colors.
Given an image and its initial segmentation, this method constructs the corresponding Region Adjacency Graph (RAG). Each node in the RAG represents a set of pixels within image with the same label in labels. The weight between two adjacent regions represents how similar or dissimilar two regions are depending on the mode parameter.
Parameters: | image : ndarray, shape(M, N, [..., P,] 3)
labels : ndarray, shape(M, N, [..., P,])
connectivity : int, optional
mode : {‘distance’, ‘similarity’}, optional
sigma : float, optional
|
---|---|
Returns: | out : RAG
|
References
[R226] | Alain Tremeau and Philippe Colantoni “Regions Adjacency Graph Applied To Color Image Segmentation” http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5274 |
Examples
>>> from skimage import data, segmentation
>>> from skimage.future import graph
>>> img = data.astronaut()
>>> labels = segmentation.slic(img)
>>> rag = graph.rag_mean_color(img, labels)
RAG
¶skimage.future.graph.
RAG
(label_image=None, connectivity=1, data=None, **attr)[source]¶Bases: networkx.classes.graph.Graph
The Region Adjacency Graph (RAG) of an image, subclasses networx.Graph
Parameters: | label_image : array of int
connectivity : int in {1, ...,
data : networkx Graph specification, optional
**attr : keyword arguments, optional
|
---|
add_edge
(u, v, attr_dict=None, **attr)[source]¶Add an edge between u and v while updating max node id.
See also
networkx.Graph.add_edge()
.
add_node
(n, attr_dict=None, **attr)[source]¶Add node n while updating the maximum node id.
See also
networkx.Graph.add_node()
.
merge_nodes
(src, dst, weight_func=<function min_weight>, in_place=True, extra_arguments=[], extra_keywords={})[source]¶Merge node src and dst.
The new combined node is adjacent to all the neighbors of src and dst. weight_func is called to decide the weight of edges incident on the new node.
Parameters: | src, dst : int
weight_func : callable, optional
in_place : bool, optional
extra_arguments : sequence, optional
extra_keywords : dictionary, optional
|
---|---|
Returns: | id : int
|
Notes
If in_place is False the resulting node has a new id, rather than dst.