Skip to main content

A Python implementation of SN-Graph algorithm.

Project description

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.

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 a non-enpdpoint spheres
  • return_sdf: Whether to return signed distance field array computed by the algorithm (neccessary to extract radii of spheres)

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sn_graph-0.2.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sn_graph-0.2.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file sn_graph-0.2.0.tar.gz.

File metadata

  • Download URL: sn_graph-0.2.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/24.2.0

File hashes

Hashes for sn_graph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d73333ad3319eae4a31abf48150c0f40097e8a00a01327fecde796bbfdcfeed1
MD5 63adb8ecfc11f139eaed4c91f5c3f911
BLAKE2b-256 3733985ecd7843447bb0d68f924c3eb37d8ef33106c4528b6d1d4517d4f5456b

See more details on using hashes here.

File details

Details for the file sn_graph-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sn_graph-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/24.2.0

File hashes

Hashes for sn_graph-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb3eea4b65108959f763270f3ece260f19e684875d680f523984e691fd8c5cdf
MD5 eb1f5aa853d9feaea6562e0bd594e04c
BLAKE2b-256 1d02ad5c45a7ada3732788e1fbf42bdf447ea7db55462aca627b6611ddee7b37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page