# Extracting Data from VMTK Centerline

**URL:** <https://discourse.slicer.org/t/extracting-data-from-vmtk-centerline/7205>\
**Category:** Support\
**Created:** [June 17, 2019, 7:00pm UTC](https://discourse.slicer.org/t/extracting-data-from-vmtk-centerline/7205 "2019-06-17T19:00:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshWilliams](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joshWilliams](https://discourse.slicer.org/u/joshWilliams)\
**Post date:** [June 17, 2019, 7:00pm UTC](https://discourse.slicer.org/t/extracting-data-from-vmtk-centerline/7205/1 "2019-06-17T19:00:07Z")

</div>

Hi,

I am using VMTK’s centreline computation tool to extract a skeleton of a respiratory system (from a stl file, converted to binary label map). I have previewed the skeleton and pressed start to begin extracting data (this took a long time, my computer thought slicer stopped responding at several intervals but I continued running - maybe this is a factor).

 ![Screenshot%20from%202019-06-17%2019-02-11](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/4/148c9d3aef1c0ab109cfa9b57dcb57261f61d200.png)

However, eventually it finished and I have this skeleton. My issue is now, **how to extract data on coordinates i.e. end points and branch points?**

The [tutorial on this](https://www.slicer.org/wiki/Modules:VMTK_in_3D_Slicer_Tutorial:_Coronary_Artery_Centerline_Extraction) uses an older version of Slicer than I have and appears fairly straight forward, however there are no clear means to extract data from the module on this version.

Any help would be greatly appreciated.

Best,  
Josh

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 17, 2019, 7:44pm UTC](https://discourse.slicer.org/t/extracting-data-from-vmtk-centerline/7205/2 "2019-06-17T19:44:25Z")

</div>

Result of centerline detection is a [vtkPolyData](https://vtk.org/doc/nightly/html/classvtkPolyData.html) that you can access by calling:

```auto
centerlineModel = getNode('CenterlineComputationModel')
centerlinePoly = centerlineModel.GetPolyData()

```

You can then access point positions as you would do for any vtkPolydata. For example:

Get first point position:

```python
centerlinePoly.GetPoints().GetPoint(0)

```

Get point IDs of the first line segment:

```python
pointIds = vtk.vtkIdList()
centerlinePoly.GetLines().GetCell(0, pointIds)

```

---

<div class="post-metadata">

**Author:** ![joshWilliams](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joshWilliams](https://discourse.slicer.org/u/joshWilliams)\
**Post date:** [June 18, 2019, 2:36pm UTC](https://discourse.slicer.org/t/extracting-data-from-vmtk-centerline/7205/3 "2019-06-18T14:36:19Z")

</div>

Thanks for your fast reply Andras. I followed your code through and it works fine up to the last line which returns nothing, as shown below:

```
>>> centerlineModel = getNode('CenterlineComputationModel')
>>> centerlinePoly = centerlineModel.GetPolyData()
>>> centerlinePoly.GetPoints().GetPoint(0)
(-236.95960998535156, 237.93817138671875, 101.977294921875)
>>> 
>>> pointIds = vtk.vtkIdList()
>>> centerlinePoly.GetLines().GetCell(0, pointIds)
>>> print centerlinePoly.GetLines().GetCell(0, pointIds)
None

```

Can you give any advice on how to proceed? My intention was to use the centerline computation to extract coordinates of centerpoints and branch points (and I was hoping these would be clearly defined in the output file for ease of scripting the recognition of this, is this so?).

Apologies but I am a complete newbie when it comes to vtk and 3D Slicer.

If it helps, I found the ID list to be empty  
`>>> pointIds = vtk.vtkIdList()`  
`>>> print pointIds`  
vtkIdList (0x6562580)  
Debug: Off  
Modified Time: 98975746  
Reference Count: 1  
Registered Events: (none)  
Number of Ids: 0

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 18, 2019, 2:39pm UTC](https://discourse.slicer.org/t/extracting-data-from-vmtk-centerline/7205/4 "2019-06-18T14:39:38Z")

</div>

`pointIds` is a [vtkIdList](https://vtk.org/doc/nightly/html/classvtkIdList.html) object, contain a list of point IDs. For example, you can get number of points in it using `GetNumberOfIds` and get Nth point ID using `GetId`. Check out [VTK examples](https://lorensen.github.io/VTKExamples/site/) site to see examples of using VTK objects in Python.
