Slicer - Convert centerlines to a graph {V,E}

Hello,

I want to convert the centerline network generated from the segmentations of the Circle of Willis into a graph data structure. Currently the only way to do it in vmtk is to use the ‘vmtknetworkextraction’ class to do so - VMTK network extraction. However, it required the input to be a surface file.

In my case, I have a centerline tree hierarchical structure already generated in slicer as shown.

I can use the .json files containing the centerline curve information to create a graph using the NetworkX library in Python. But is there a way to directly convert the Centerline model_1.vtk file into a graph using the connectivity information stored as an ordered dictionary?

I am using the following code to get numpy arrays from the vtk file.

# Using vmtk
filename = 'Centerline model_1.vtk'
centerlineReader = vmtkscripts.vmtkSurfaceReader()
centerlineReader.InputFileName = filename
centerlineReader.Execute()
clNumpyAdaptor = vmtkscripts.vmtkCenterlinesToNumpy()
clNumpyAdaptor.Centerlines = centerlineReader.Surface
clNumpyAdaptor.Execute()
numpyCenterlines = clNumpyAdaptor.ArrayDict

I get the following as an output:
Points:
image

PointData:

What does ‘EdgeArray’ and ‘EdgePCoordarray’ mean here? How do they represent the edge connectivity of the 1D centerline tree?
image

CellData:

Thank you!

You could easily add an option to the Extract Centerline module in Slicer to create the graph representation you need. See source code here that generates a hierarchy of curves, with a little change you can put the point lists into a Python dictionary instead. If you send a pull request with the proposed changes then we’ll be happy to merge it.

Thank you @lassoan for the piece of code. Yes I will send out a pull request with the proposed changes soon.

Moreover, I also wanted to know if scalar values of ‘GroupIDsarray’, ‘TortuosityArray’ , ‘BlankingArray’ etc. can be incorporated in the centerline model. I generated the following plots by using the conventional vmtkscripts, but it does not always work correctly.


Currently there are only 3 ways to postprocess the centerline data as shown here.

  • However, can we make any changes here in the base code to store values of other arrays as well?

  • Also would it be possible to run this function independently in a separate python code given the vtkpolymesh surface data and the endpoint co ordinates?

This has been done for the network curves but the centerline curves hold the real information.

Yes, sure. These are cell data (one value for each branch) and the values are saved in the table where you can easily look them up (by cell ID) but feel free to add it to the centerline tree model as well. Send a pull request with the proposed changes.

Yes, just send a pull request if you have any suggestion.

You can use the module from anywhere (from a Python script, without a GUI; from Jupyter notebooks, etc.). See complete example here: