A Python implementation of SN-Graph algorithm.
Project description
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.
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)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sn_graph-0.3.0.tar.gz.
File metadata
- Download URL: sn_graph-0.3.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.7 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56bcfdc50b4a59f7bf3c9e203142b58ba501200b9c9a29f893bc3d9a973fef71
|
|
| MD5 |
be08be671f20147c5dc793a8dcccc409
|
|
| BLAKE2b-256 |
ad4d74f4736163f3348adbbecc867ef6768fad6cf765d0177f9912e142ae6732
|
File details
Details for the file sn_graph-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sn_graph-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4ad50944794732db2f0ca24ec100b1ef8fa17d49abe8eee3d35e97c0b33a287
|
|
| MD5 |
530930cf51eaee063fbfc36f9a47057d
|
|
| BLAKE2b-256 |
65622108e3d63a5f93ad38fda3ed83af2559c97a4a13a7e6d9e9647ac5ec7a26
|