{"id":13443864,"url":"https://github.com/Image-Py/sknw","last_synced_at":"2025-03-20T17:32:07.924Z","repository":{"id":43028144,"uuid":"94714688","full_name":"Image-Py/sknw","owner":"Image-Py","description":"build net work from skeleton image (2D-3D)","archived":false,"fork":false,"pushed_at":"2022-03-23T12:18:01.000Z","size":17,"stargazers_count":230,"open_issues_count":22,"forks_count":48,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-17T10:06:00.750Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Image-Py.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-18T21:41:54.000Z","updated_at":"2025-02-06T08:22:34.000Z","dependencies_parsed_at":"2022-09-07T01:41:23.210Z","dependency_job_id":null,"html_url":"https://github.com/Image-Py/sknw","commit_stats":null,"previous_names":["yxdragon/sknw"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Image-Py%2Fsknw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Image-Py%2Fsknw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Image-Py%2Fsknw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Image-Py%2Fsknw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Image-Py","download_url":"https://codeload.github.com/Image-Py/sknw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244660618,"owners_count":20489366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:02:12.388Z","updated_at":"2025-03-20T17:32:02.916Z","avatar_url":"https://github.com/Image-Py.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"Skeleton Network\n======================\nbuild net work from nd skeleton image\n\n### graph = sknw.build_sknw(ske， multi=False, iso=True, ring=True, full=True)\n\u003e **ske:** should be a nd skeleton image\n\u003e \n\u003e **multi:** if True，a multigraph is retured, which allows more than one edge between two nodes and self-self edge.\n\u003e\n\u003e **iso:** if True, return one-pixel node\n\u003e\n\u003e **ring:** if True, return ring without any branch (and insert a self-connected node in the ring)\n\u003e\n\u003e **full:** if True, every edge start from the node's centroid. else touch the node block but not from the centroid.\n\u003e \n\u003e **return:** is a networkx Graph object\n\n![image](https://user-images.githubusercontent.com/24822467/144245690-8def3215-344f-464c-a825-bc33568758f7.png)\n\n### graph detail:\n\u003e **graph.nodes[id]['pts'] :** Numpy(x, n), coordinates of nodes points\n\u003e \n\u003e **graph.nodes[id]['o']:** Numpy(n), centroid of the node\n\u003e \n\u003e **graph.edge(id1, id2)['pts']:** Numpy(x, n), sequence of the edge point\n\u003e \n\u003e **graph.edge(id1, id2)['weight']:** float, length of this edge\n\u003e \n\u003e *if  it's a multigraph, you must add a index after two node id to get the edge, like: graph.edge(id1, id2)[0].*\n### Build Graph:\nbuild Graph by Skeleton, then plot as a vector Graph in matplotlib.\n```python\nfrom skimage.morphology import skeletonize\nfrom skimage import data\nimport sknw\n\n# open and skeletonize\nimg = data.horse()\nske = skeletonize(~img).astype(np.uint16)\n\n# build graph from skeleton\ngraph = sknw.build_sknw(ske)\n\n# draw image\nplt.imshow(img, cmap='gray')\n\n# draw edges by pts\nfor (s,e) in graph.edges():\n    ps = graph[s][e]['pts']\n    plt.plot(ps[:,1], ps[:,0], 'green')\n    \n# draw node by o\nnodes = graph.nodes()\nps = np.array([nodes[i]['o'] for i in nodes])\nplt.plot(ps[:,1], ps[:,0], 'r.')\n\n# title and show\nplt.title('Build Graph')\nplt.show()\n```\n![](http://home.imagepy.org/sknw/buildgraph.png \"解压\")\n### Find Path\nthen you can use networkx do what you want\n![](http://home.imagepy.org/sknw/findpath.png \"解压\")\n### 3D Skeleton\nsknw can works on nd image, this is a 3d demo by mayavi\n![](http://home.imagepy.org/sknw/3dgraph.png \"解压\")\n\n### About ImagePy\n[https://github.com/Image-Py/imagepy](https://github.com/Image-Py/imagepy)\n\nImagePy is my opensource image processihng framework. It is the ImageJ of Python, you can wrap any numpy based function esaily. And sknw is a sub module of ImagePy. You can use sknw without any code.\n\n![](http://myvi.imagepy.org/imgs/imagepy.jpg \"vessel\")","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FImage-Py%2Fsknw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FImage-Py%2Fsknw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FImage-Py%2Fsknw/lists"}