SN-Graph: a graph skeletonisation algorithm.
A Python implementation of an SN-Graph skeletonisation algorithm. Based on the article SN-Graph: a Minimalist 3D Object Representation for Classification arXiv:2105.14784.
Description
Given a binary image/volume representing a shape, SN-Graph works by:
- Creating vertices as centres of spheres inscribed in the shape, where one balances the size of the spheres with their coverage of the shape, and pariwise distances from one another.
- Adding edges between the neighbouring spheres, subject to a few common-sense criteria.
The resulting graph serves as a lightweight 1-dimensional representation of the original image, potentially useful for further analysis.
Documentation
For documentation see docs.
For API reference see api_reference.
Bug reports, improvements, and pull requests are welcome. See CONTRIBUTING.md to get started.
Installation
pip install sn-graph
or
poetry add sn-graph
Basic Usage
See notebooks demo_sn-graph and 3d_demo for 2D and 3D demo, respectively. Notebook mnist_classification has some good stuff too!
import numpy as np
import sn_graph as sn
# Create a simple square image
img = np.zeros((256, 256))
img[20:236, 20:236] = 1 # Create a square region
# Generate the SN graph
centers, edges, sdf_array = sn.create_sn_graph(
img,
max_num_vertices=15,
minimal_sphere_radius=1.0,
return_sdf=True
)
import matplotlib.pyplot as plt
#Draw graph on top of the image and plot it
graph_image=sn.draw_sn_graph(centers, edges, sdf_array, background_image=img)
plt.imshow(graph_image)
plt.show()
Key Parameters
max_num_vertices: Maximum number of vertices in the graphmax_edge_length: Maximum allowed edge lengthedge_threshold: Threshold for determining what portion of an edge must be contained within the shapeminimal_sphere_radius: Minimum radius allowed for spheresedge_sphere_threshold: Threshold value for deciding how close can an edge be to non-enpdpoint spheresreturn_sdf: Whether to return signed distance field array computed by the algorithm (neccessary to extract radii of spheres)
Authors
- Tomasz Prytuła (tomasz.prytula@alexandra.dk)
Metadata
Release files for sn-graph 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sn_graph-0.4.1.tar.gz | 11.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sn_graph-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / sn_graph-0.4.1.tar.gz
| Download URL | sn_graph-0.4.1.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae01240a57516ed8c8a0a0187b555e2b62a31f5832e7ac841de06df524fc64c4
|
|
BLAKE2b-256 checksum How to use checksums |
ced76e4cc6f3f4148a6e0f78c4525cd9ccfdccefbafe430465e3d4761dae1cc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.
Transparency logRelease files / sn_graph-0.4.1-py3-none-any.whl
| Download URL | sn_graph-0.4.1-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59b37f79b3859ec6749d21361ea1c82aa7ad992bd7c822e0c5055a105e40ee07
|
|
BLAKE2b-256 checksum How to use checksums |
c14058bbb40e0879e53da697fbeeedbbf4a6a0f3f218b48b01367043adb2d053
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.
Transparency log