Skip to content

Commit 6cc8daa

Browse files
authored
Merge pull request #9 from alexandrainst/8-add-installation-and-fix-image-loading-in-readme
8 add installation and fix image loading in readme
2 parents 224931f + fd7f15c commit 6cc8daa

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

README.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,57 @@
33
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](https://arxiv.org/abs/2105.14784).
44

55

6-
![Example of a binary image and the skeletal graph](/assets/horse_graph.png "SN-graph generated out of an scikit-image's horse image.")
6+
![Example of a binary image and the skeletal graph](https://raw.githubusercontent.com/alexandrainst/sn-graph/main/assets/horse_graph.png "SN-graph generated out of an scikit-image's horse image.")
77

88
## Description
99

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

12-
1. Creating vertices as centres of spheres inscribed in the image, where one balances the size of the spheres with their coverage of the shape, and pariwise distances from one another.
12+
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.
1313
3. Adding edges between the neighbouring spheres, subject to a few common-sense criteria.
1414

1515
The resulting graph serves as a lightweight 1-dimensional representation of the original image, potentially useful for further analysis.
1616

17+
## Installation
18+
19+
```bash
20+
pip install sn-graph
21+
```
22+
or
23+
24+
```bash
25+
poetry add sn-graph
26+
```
27+
1728
## Basic Usage
1829

30+
See notebooks [demo_sn-graph](notebooks/demo_sn-graph.ipynb) and [3d_demo](notebooks/3D_demo.ipynb) for 2D and 3D demo, respectively. Notebook [mnist_classification](notebooks/mnist_classification.ipynb) has some good stuff too!
31+
1932
```python
2033
import numpy as np
2134
import sn_graph as sn
2235

2336
# Create a simple square image
24-
img = np.zeros((100, 100))
25-
img[40:60, 40:60] = 1 # Create a square region
37+
img = np.zeros((256, 256))
38+
img[20:236, 20:236] = 1 # Create a square region
2639

2740
# Generate the SN graph
28-
centers, edges = sn.create_sn_graph(
41+
centers, edges, sdf_array = sn.create_sn_graph(
2942
img,
30-
max_num_vertices=10,
31-
edge_threshold=1.0
43+
max_num_vertices=15,
44+
minimal_sphere_radius=1.0,
45+
return_sdf=True
3246
)
3347

48+
import matplotlib.pyplot as plt
49+
50+
#Draw graph on top of the image and plot it
51+
graph_image=sn.draw_sn_graph(centers, edges, sdf_array, background_image=img)
52+
53+
plt.imshow(graph_image)
54+
plt.show()
3455
```
56+
<img src="https://raw.githubusercontent.com/alexandrainst/sn-graph/main/assets/square_readme.png" alt="SN-Graph drawn on top of the square" width="500">
3557

3658
## Key Parameters
3759

@@ -40,6 +62,7 @@ centers, edges = sn.create_sn_graph(
4062
- `edge_threshold`: Threshold for determining what portion of an edge must be contained within the shape
4163
- `minimal_sphere_radius`: Minimum radius allowed for spheres
4264
- `edge_sphere_threshold`: Threshold value for deciding how close can an edge be to a non-enpdpoint spheres
65+
- `return_sdf`: Whether to return signed distance field array computed by the algorithm (neccessary to extract radii of spheres)
4366

4467
## Authors
4568
- Tomasz Prytuła (<tomasz.prytula@alexandra.dk>)

assets/square_readme.png

47.6 KB
Loading

notebooks/3D_demo.ipynb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## A 3d Demo\n",
8+
"\n",
9+
"The notebook shows how to extract SN-Graph out of a 3D volume."
10+
]
11+
},
312
{
413
"cell_type": "code",
514
"execution_count": null,
@@ -28,7 +37,7 @@
2837
"metadata": {},
2938
"outputs": [],
3039
"source": [
31-
"# local voxelise allos to fill the inside of the mesh with positive values\n",
40+
"# local voxelise allows to fill the inside of the mesh with positive values which is needed for sdf computation\n",
3241
"voxels = trimesh.voxel.creation.local_voxelize(\n",
3342
" mesh, point=(0, 0, 0), radius=300, pitch=0.5, fill=True\n",
3443
")\n",

notebooks/mnist_classification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"## A Mnist classification using skeletal graphs. \n",
88
"\n",
9-
"A demo on using SN-graphs as inputs to Graph Nueral Networks. The model achieves roughly 90% accuracy, "
9+
"A demo on using SN-graphs as inputs to Graph Neural Networks. The model achieves roughly 90% accuracy, "
1010
]
1111
},
1212
{

0 commit comments

Comments
 (0)