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.

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.0

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.0
File Size Uploaded
sn_graph-0.4.0.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sn-graph 0.4.0
File Interpreter ABI Platform
sn_graph-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.3 kB

Release files / sn_graph-0.4.0.tar.gz

Download URL sn_graph-0.4.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b5cd1fbd9fde1cd567c5f0eb774ccbe903aef7d852004dca5ae665ce4efec722
BLAKE2b-256 checksum
How to use checksums
83140e04164ec08ecdfb743a7a7b4fec07b5c0c28afe118c793a65df470fbaaf
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 15, 2026.

Transparency log

Release files / sn_graph-0.4.0-py3-none-any.whl

Download URL sn_graph-0.4.0-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f2d43689d509dc458999219f1a8f4b1c25a6d1926428fba1b000ee8c5942cef
BLAKE2b-256 checksum
How to use checksums
c8f4822e708f6c488a17b22d6a352d55d3d5f0ae9183a4bf5ed49abc6b2002ca
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 15, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.1

2 release files

This release

0.4.0 This release

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