GraphProcessing#

Module providing tools to create and manipulate graphs. Functions include graph construction from skeletons, simplification, reduction and clean-up of graphs.

clean_graph(graph, remove_self_loops=True, remove_isolated_vertices=True, vertex_mappings={'coordinates': <function mean_vertex_coordinates>, 'radii': <function max>}, verbose=False)[source]#

Remove all cliques to get pure branch structure of a graph.

Arguments

graphGraph

The graph to clean up.

verbosebool

If True, prin progress information.

Returns

graphGraph

A graph removed of all cliques.

Note

cliques are replaced by a single vertex connecting to all non-clique neighbours The center coordinate is used for that vertex as the coordinate.

expand_graph(graph)[source]#
expand_graph_length(graph, length='length', return_edge_mapping=False)[source]#

Expand a reduced graph to a full graph.

graph_from_skeleton(skeleton, points=None, radii=None, vertex_coordinates=True, check_border=True, delete_border=False, verbose=False)[source]#

Converts a binary skeleton image to a graph-tool graph.

Arguments

skeletonarray

Source with 2d/3d binary skeleton.

pointsarray

List of skeleton points as 1d indices of flat skeleton array (optional to save processing time).

radiiarray

List of radii associated with each vertex.

vertex_coordinatesbool

If True, store coordiantes of the vertices / edges.

check_borderbool

If True, check if the boder is empty. The algorithm reuqires this.

delete_borderbool

If True, delete the border.

verbosebool

If True, print progress information.

Returns

graphGraph class

The graph corresponding to the skeleton.

Note

Edges are detected between neighbouring foreground pixels using 26-connectivty.

graph_to_skeleton(graph, sink=None, dtype=<class 'bool'>, values=True)[source]#

Create a binary skeleton from a graph.

mean_vertex_coordinates(coordinates)[source]#
reduce_graph(graph, vertex_to_edge_mappings={'radii': <function max>}, edge_to_edge_mappings={'length': <function sum>}, edge_geometry=True, edge_length=None, edge_geometry_vertex_properties=['coordinates', 'radii'], edge_geometry_edge_properties=None, return_maps=False, verbose=False)[source]#

Reduce graph by replacing all vertices with degree two.

trace_edge_label(graph, edge_label, condition, max_iterations=None, dilation_steps=1, pass_label=False, **condition_args)[source]#

Traces label within a graph.

Arguments

edge_labelarray

Start label.

conditionfunction(graph, vertex)

A function determining if the vertex should be added to the labels.

stepsint

Number edges to jump to find new neighbours. Default is 1.

Returns

edge_labelarray

The traced label.

trace_vertex_label(graph, vertex_label, condition, dilation_steps=1, max_iterations=None, pass_label=False, **condition_args)[source]#

Traces label within a graph.

Arguments

vertex_labelarray

Start label.

conditionfunction(graph, vertex)

A function determining if the vertex should be added to the labels.

stepsint

Number edges to jump to find new neighbours. Default is 1.

Returns

vertex_labelarray

The traced label.