{"id":20221660,"url":"https://github.com/phcerdan/sgext","last_synced_at":"2025-10-27T19:40:23.057Z","repository":{"id":206391700,"uuid":"54013137","full_name":"phcerdan/SGEXT","owner":"phcerdan","description":"Spatial Graph Extractor. Library and scripts to study graphs extracted from binary images, or to generate graphs and analyze them completely in-silico. Used at least in biopolymers simulations and vascular networks.","archived":false,"fork":false,"pushed_at":"2025-01-25T06:11:03.000Z","size":21698,"stargazers_count":5,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-20T18:20:00.887Z","etag":null,"topics":["binarization","dgtal","distance-map","generator","graph","graph-processing","hacktoberfest","image-processing","itk","python","segmentation","skeletonization","spatial-graph","thin","thinning","topology","vtk"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phcerdan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-03-16T08:17:54.000Z","updated_at":"2025-01-25T06:11:08.000Z","dependencies_parsed_at":"2025-04-10T16:50:28.026Z","dependency_job_id":null,"html_url":"https://github.com/phcerdan/SGEXT","commit_stats":{"total_commits":641,"total_committers":1,"mean_commits":641.0,"dds":0.0,"last_synced_commit":"df933fab1d084110dba84413cd2028dfe2717ad3"},"previous_names":["phcerdan/sgext"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/phcerdan/SGEXT","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcerdan%2FSGEXT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcerdan%2FSGEXT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcerdan%2FSGEXT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcerdan%2FSGEXT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phcerdan","download_url":"https://codeload.github.com/phcerdan/SGEXT/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phcerdan%2FSGEXT/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266151524,"owners_count":23884436,"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":["binarization","dgtal","distance-map","generator","graph","graph-processing","hacktoberfest","image-processing","itk","python","segmentation","skeletonization","spatial-graph","thin","thinning","topology","vtk"],"created_at":"2024-11-14T06:53:57.770Z","updated_at":"2025-10-27T19:40:18.023Z","avatar_url":"https://github.com/phcerdan.png","language":"C++","readme":"[![Build Status](https://dev.azure.com/phcerdan/SGEXT/_apis/build/status/phcerdan.SGEXT?branchName=master)](https://dev.azure.com/phcerdan/SGEXT/_build/latest?definitionId=2\u0026branchName=master)\n\n# SGEXT\n\n**S**patial**G**raph **Ext**ractor.\n\nLibrary with utilities to handle graphs extracted from binary images.\n\nProvides scripts to generate a thin/skeletonized image from binary images (segmentations).\nA thin image is a one pixel wide image, conserving the same topology (same number of holes, and shapes) than the input binary image.\n\nA distance map can be used for the thin image to be in the centerline of the input.\n\nThe thinning algorithm used was contributed by the author to the DGtal library, based on the work of Couprie and Bertrand [1]\n\nThe thin output can also be converted to a Spatial Graph, this is a regular graph, an adjacency list holding the nodes and edges, plus all the geometrical information. In the case of a nodes/vertices, a spatial node with 3D location. In edges, a spatial edge, a data structure with a consecutive list of points connecting the nodes.\n\nUsing histo.hpp from: https://github.com/phcerdan/histo-header\nSHA: 556ada3ff79c0180a0cbec36ff29a30da5acb367\n\n## Python\n\nSGEXT is wrapped to python using pybind11, and uploaded regularly to pypi for all platforms (Linux, Windows, MacOS)\nand multiple `python` version (from `3.5` to latest) using azure-pipelines.\n\n```\npip install sgext\n```\n\n```python\nimport sgext\n# Read image from file into a sgext_image\ninput_filename=\"/path/to/binary_image.nrrd\" # or any format that ITK can read\nsgext_image = sgext.itk.read_as_binary(input_filename)\n# Or from a numpy array:\nsgext_image = sgext.itk.IUC3P()\nsgext_image.from_pyarray(mask)\n# Or convert from an existing ITK image via the numpy bridge:\nsgext_image = sgext.itk.IUC3P()\nsgext_image.from_pyarray(itk.GetArrayFromImage(itk_image))\nthin_image = sgext.scripts.thin(input=sgext_image,\n                   tables_folder= sgext.tables_folder,\n                   skel_type=\"end\",\n                   select_type=\"first\",\n                   persistence=2,\n                   visualize=False,\n                   verbose=True\n                   )\nthin_filename =\"/path/to/thin_image.nrrd\"\nsgext.itk.write(thin_image, thin_filename)\n```\n\n## Usage\nThe C++ scripts are in folder `cpp-scripts`.\nThe inputImage to these scripts is a label/binary image or sometimes a float grayscale image.\nAll the scripts provide a --help or -h option for guidance.\n\n### Distance Map\nCreate a distance map using DGtal most precise way with Lp metric. The output is a float/double image with pixels storing the distance to the background (heavy image).\n```bash\ncreate_distance_map \\\n    -i inputImage.nrrd \\\n    -o outputFolder \\\n    -v # verbose flag --recommended--\n```\n\nIn verbose mode, the output would be:\n```bash\nNew Block [Create Distance Map]\nEndBlock [Create Distance Map] (108686 ms)\nTime elapsed: 108\n```\n\nthe outputFolder will be populated with `inputImage_DMAP.nrrd` (heavy image).\n\n### Thinning\nUsing VoxelComplex in DGtal, based on Bertrand and Couprie research in digital topology. Ensures topology consistency,\nand implements a way to perform a prunning on the branches based on local information.\n```bash\nthin \\\n    -i inputImage.nrrd \\\n    -o outputFolder \\\n    -s 1isthmus \\\n    -c dmax \\ # Requires distance map, ensures centrality of the thinning\n    -d distanceMapImage.nrrd \\\n#    -p 2 \\ Optional persistence, useful for noisy images, default to 0.\n    -v # verbose flag --recommended--\n```\n\n### Get radius of vesselnes\nThe distance map can also be used as a really good approximation to vesselnes radius. In order to get this information\nfor our skeletonized image we can use the script mask_distance_map_with_thin_image\n\n```bash\nmask_distance_map_with_thin_image \\\n    -i inputDistanceMapImage.nrrd \\\n    -m inputSkeletonizedImage.nrrd \\\n    -o outputFolder \\\n    -v # verbose flag --recommended--\n```\n\nThis will generate an image `skeletonizedImage_DMAP_MASKED` in the output folder\n\n### Graph processing\nTo convert the skeletonized image into a graph we used boost graph. The following script\n\n```bash\nanalyze_graph \\\n    -i inputSkeletonizedImage.nrrd\n    -o outputFolder \\ # This will generate a .dot file with all the graph information\n    -r \\ # reduce graph, convert chain nodes (degree 2) into edge points.\n    -c \\ # removeExtraEdges (remove edges created because full connectivity)\n    -m \\ # mergeThreeConnectedNodes\n    -v\n```\nMore options are possible, use `--help` for details.\n\n\n## Contributors\n\n- Pablo Hernandez-Cerdan\n\n[1]: Couprie and Bertrand, “Asymmetric Parallel 3D Thinning Scheme and Algorithms Based on Isthmuses.” Pattern Recognition Letters. June,  2016. DOI:10.1016/j.patrec.2015.03.014\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphcerdan%2Fsgext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphcerdan%2Fsgext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphcerdan%2Fsgext/lists"}