API Reference
create_sn_graph(image, max_num_vertices=-1, edge_threshold=1.0, max_edge_length=-1, minimal_sphere_radius=5.0, edge_sphere_threshold=1.0, return_sdf=False)
Create a graph from an image/volume using the Sphere-Node (SN) graph skeletonisation algorithm.
This function converts a grayscale (or binary) image/volume into a graph representation by first computing its signed distance field (assuming boundary contour has value 0), then placing sphere centers as vertices and creating edges between neighboring spheres based on specified criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Input image/volume where the foreground is positive and the background is 0. Can be a numpy array of arbitrary dimension. |
required |
max_num_vertices
|
int
|
Maximum number of vertices (sphere centers) to generate. If -1, no limit is applied. Defaults to -1. |
-1
|
edge_threshold
|
float
|
Threshold value for determining the minimal portion of an edge that must lie within the object. Higher value is more restrictive, with 1 requiring edge to be fully contained in the object. Defaults to 1.0. |
1.0
|
max_edge_length
|
int
|
Maximum allowed length for edges between vertices. If -1, no limit is applied. Defaults to -1. |
-1
|
minimal_sphere_radius
|
float
|
Minimum radius allowed for spheres when placing vertices. Defaults to 5. |
5.0
|
edge_sphere_threshold
|
float
|
Threshold value for determining the minimum allowable distance between an edge and non-endpoint spheres. Higher value is more restrictive, with 1 allowing no overlap whatsoever. Defaults to 1.0. |
1.0
|
return_sdf
|
bool
|
If True, the signed distance field array is returned as well. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
Union[Tuple[List[Tuple[int, ...]], List[Tuple[Tuple[int, ...], ...]], ndarray], Tuple[List[Tuple[int, ...]], List[Tuple[Tuple[int, ...], ...]]]]
|
A tuple containing a list of sphere centers as coordinate tuples, a list of edges as pairs of vertex coordinates, and a signed distance field array if return_sdf is True. |
Source code in src/sn_graph/core.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
draw_sn_graph(spheres_centres, edges, sdf_array=None, background_image=None)
Draw a graph of spheres and edges on an image/volume (or on a blank background). The function creates a monochromatic volume of dimension equal to the dimension of the graph. Value 0 is given to the background, value 1 to the background image/volume, value 2 to the edges, and value 4 to the spheres.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spheres_centres
|
list
|
list of tuples, each tuple contains coordinates of a sphere's centre. |
required |
edges
|
list
|
list of tuples of tuples, each tuple contains coordinates of the two endpoints of an edge. |
required |
sdf_array
|
optional(ndarray)
|
the signed distance field array, if not provided no spheres will be drawn. |
None
|
background_image
|
optional(ndarray)
|
the image/volume on which to draw the graph. If not provided and if sdf_array is not provided either, a blank background will be created with the size inferred from the coordinates of the graph vertices. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
the image/volume (or a blank background) with the graph drawn on it. |
Raises:
Type | Description |
---|---|
ValueError
|
if the shape of |
Source code in src/sn_graph/visualisation.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
visualize_3d_graph(spheres_centres, edges, sdf_array=None)
Visualize a 3D graph with vertices, edges, and spheres by creating a trimesh scene object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spheres_centres
|
list
|
list of coordinate tuples [(x1,y1,z1), (x2,y2,z2), ...] |
required |
edges
|
list
|
list of tuples of coordinates for start and end of edges [((x1,y1,z1), (x2,y2,z2)), ...] |
required |
sdf_array
|
optional(ndarray)
|
array that can be queried at vertex coordinates to get radius, if not provided, no spheres will be drawn |
None
|
Returns:
Name | Type | Description |
---|---|---|
scene |
Scene
|
A 3D scene containing the graph visualization. |
Source code in src/sn_graph/visualisation.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|