Skip to main content

SN-Graph: a graph skeletonisation algorithm.

build Coverage Report Pre-commit PyPI - Version License

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.

Example of a binary image and the skeletal graph

Description

Given a binary image/volume representing a shape, SN-Graph works by:

  1. 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.
  2. 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()
SN-Graph drawn on top of the square

Key Parameters

  • max_num_vertices: Maximum number of vertices in the graph
  • max_edge_length: Maximum allowed edge length
  • edge_threshold: Threshold for determining what portion of an edge must be contained within the shape
  • minimal_sphere_radius: Minimum radius allowed for spheres
  • edge_sphere_threshold: Threshold value for deciding how close can an edge be to non-enpdpoint spheres
  • return_sdf: Whether to return signed distance field array computed by the algorithm (neccessary to extract radii of spheres)

Authors

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)

Source distribution for sn-graph 0.4.1
File Size Uploaded
sn_graph-0.4.1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sn-graph 0.4.1
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page