Skip to content
Sprith-JPublic

About

Inspectable graphs from 3D vessel skeletons, with physical geometry, structural QC, and a synthetic demo.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

GraphSkel

Inspectable graphs from 3D vessel skeletons.

GraphSkel converts a binary vessel mask and its centerline skeleton into a multigraph with ordered 3D polylines. It exports node and edge tables, physical lengths, tortuosity, label volumes, and structural quality flags.

The backend comes from my OCT angiography research workflow. This small project provides a standalone Python interface and a reproducible synthetic example.

A synthetic vessel mask, its skeleton, and the extracted graph with endpoint and junction markers.

Quick start

Python 3.9 or later, on Windows, Linux, or macOS:

git clone https://github.com/Sprith-J/GraphSkel.git
cd GraphSkel
python -m pip install -e .
python -m graphskel demo --output outputs/demo

The demo creates the input NIfTI files, graph tables, and two preview images. It uses a fully synthetic branching phantom: 9 nodes, 8 edges, one connected component, with every skeleton voxel represented by a node region or edge.

The installed graphskel command is equivalent to python -m graphskel.

Use your own volumes

Provide a vessel mask and an existing, one-voxel-thick skeleton on the same 3D grid. Positive values indicate foreground. Specify the voxel spacing in micrometres, in array-axis order: row, column, slice.

python -m graphskel analyze --mask mask.nii.gz --skeleton skeleton.nii.gz --spacing 2 2 2.615 --output outputs/my_graph

Or use the Python interface:

from graphskel import build_graph

report = build_graph(
    "mask.nii.gz",
    "skeleton.nii.gz",
    "outputs/my_graph",
    spacing_um_rcs=(2.0, 2.0, 2.615),
)
print(report["node_count"], report["edge_count"])

The example spacing above is illustrative; use the values for your own images. Inputs are read without modification, and each run requires a new output folder.

What the graph contains

  • Adjacent branch voxels form junction regions; endpoints and isolated voxels become nodes.
  • Ordered centerline paths become edges with unique IDs. Self-loops and parallel edges remain in the multigraph.
  • Lengths use anisotropic voxel spacing. Tortuosity is polyline length divided by endpoint chord length; a closed loop has an undefined chord-based ratio.
  • Structural flags identify short edges, boundary contact, cycles, complex junctions, and possible axial bridges for review.
  • A graph report checks polyline continuity, node references, incidence, label consistency, and skeleton coverage.

The same synthetic graph shown in 3D physical coordinates and as a labelled connectivity network. Edge colour indicates polyline length.

Outputs

File Contents
graph_nodes.csv Node ID, type, component, position, degree, and flags
graph_edges.csv Edge endpoints, ordered coordinates, length, tortuosity, and flags
graph_polylines.jsonl Ordered [row, column, slice] coordinates for each edge
graph_incidence.csv Node–edge incidence, including both ends of self-loops
graph_sparse_adjacency.csv Edge-indexed adjacency table
graph_*_label_map.nii.gz Node and edge labels on the original grid
graph_structural_qc_map.nii.gz Bit-coded structural review flags
graph_contract_report.json Structural validation results and timings
graph_v1.mat Node and edge tables for MATLAB
travel_path_smoke_test.json A length-weighted example shortest path

Output tables and polylines use 1-based row/column/slice indices. Physical XYZ coordinates use a local origin: X = column × column_spacing, Y = row × row_spacing, Z = slice × slice_spacing, after subtracting one from the stored indices. NIfTI affines are retained for image alignment; the exported coordinates are local grid coordinates.

Interpretation

GraphSkel represents the supplied skeleton using 26-neighbour connectivity. Dense voxel junctions are grouped into node regions, so skeleton preparation and local topology affect the resulting graph. QC flags support review; skeleton coverage measures representation of the input, rather than anatomical accuracy. The demo demonstrates geometry and software behaviour using synthetic data.

Tests and implementation

python -m unittest discover -s tests -v

Tests cover anisotropic length and axis conventions, branching, closed loops, parallel paths, disconnected/isolated components, and input/output protection. See implementation notes for the extraction logic and the demo summary for the published example.

Built with NumPy, SciPy, NiBabel, pandas, NetworkX, Matplotlib, and psutil.

Hengming Jing · Academic homepage

中文简介

GraphSkel 将三维血管 mask 与骨架转换为可检查的图结构,导出节点、边、 物理长度、迂曲度和质量标记。项目从本地 OCTA 分析流程提取,演示完全使用 合成数据。运行示例即可生成输入、结果表和两张演示图。

About

Inspectable graphs from 3D vessel skeletons, with physical geometry, structural QC, and a synthetic demo.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages