# Problem in extracting centerlines

**URL:** https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551
**Category:** Support
**Tags:** segmentation, centerlines
**Created:** [September 18, 2020, 4:09pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551 "2020-09-18T16:09:50Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)
#### Post date: [September 18, 2020, 4:09pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/1 "2020-09-18T16:09:50Z")

</div>

Hello All,

I am trying to extract centerlines of vessel segments present in an [stl file](https://drive.google.com/file/d/1pSMQWkjCVzUwPHsjFEAcqzdJddv_87WP/view?usp=sharing). When I use this model in the extract centerline module all the endpoints are not detected after hitting Auto-detect.

I also tried the same on a smaller subset of the vessels present in the stl file shared above. The network extraction and centerline extraction didn’t find the properties of all the branches. Many endpoints are undetected in “Auto detect”.

Suggestions on how to get this working will be really helpful.

---

<div class="post-metadata">

### Author: ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)
#### Post date: [September 22, 2020, 3:21pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/2 "2020-09-22T15:21:10Z")

</div>

This is a kind reminder.

---

<div class="post-metadata">

### Author: ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)
#### Post date: [September 27, 2020, 4:26pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/3 "2020-09-27T16:26:21Z")

</div>

This is a kind reminder. I’d like to know if the centerline extraction will work on geometries like this

---

<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: [September 28, 2020, 5:25am UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/4 "2020-09-28T05:25:28Z")

</div>

These file contains a so badly corrupted mesh that it is really hard to make any sense of it. It is tricky because visually it looks OK. However, it has duplicate triangles all over the mesh (it looks like all the tubes are double-walled) and it self-intersects at hundreds of locations. If you got this from an attachment of a paper then I would suggest to contact the journal and/or the authors and ask for a corrected mesh. Or ask for the centerline that it was generated from.

I was able to make the mesh somewhat usable by using [ParaView](https://www.paraview.org/)’s “Clean to grid” filter followed by “Extract surface”. However, it is still not perfect and VMTK can only process a single vessel tree at a time, so you need to tune mesh clearing further and to split the mesh to independent trees before attempting centerline analysis.

---

<div class="post-metadata">

### Author: ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)
#### Post date: [September 28, 2020, 6:28am UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/5 "2020-09-28T06:28:50Z")

</div>

Thanks a lot for looking into this.

> [@lassoan](#):
>
> Or ask for the centerline that it was generated from.

The centerline data of multiple trees are available in [xml file](https://github.com/DeepaMahm/misc/blob/master/islet1.xml).  
Each `<vessel version="3" color="#6080FF" type="directed">` corresponds a single tree.  
I have parsed this data in Python. However, I am not sure how to compute the centerline lengths and diameter / generate stl file from this data. Any help will be greatly appreciated.

The 3D object file of a single tree is also available [here](https://drive.google.com/file/d/1ixPXpNiJyR2A60q15ldc_GFDKVfF8oRv/view?usp=sharing)

> [@lassoan](#):
>
> I was able to make the mesh somewhat usable by using [ParaView](https://www.paraview.org/)’s “Clean to grid” filter followed by “Extract surface”.

I will try if this works on the single tree object.

EDIT: I used “Clean to grid” filter followed by “Extract surface” and generated [this file](https://drive.google.com/file/d/1ILuFBIT5dNrxu0JQUcKDuK0uXiz8exYD/view?usp=sharing)  
The endpoints weren’t detected for this too

---

<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: [September 28, 2020, 1:52pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/6 "2020-09-28T13:52:03Z")

</div>

> [@Deepa](#):
>
> The centerline data of multiple trees are available in [xml file](https://github.com/DeepaMahm/misc/blob/master/islet1.xml).  
> Each `<vessel version="3" color="#6080FF" type="directed">` corresponds a single tree.  
> I have parsed this data in Python. However, I am not sure how to compute the centerline lengths and diameter / generate stl file from this data. Any help will be greatly appreciated.

Having a tree in XML makes things very simple. Centerline length computation is trivial (sum of Euclidean distances between points that make up a branch).

> [@Deepa](#):
>
> > [@lassoan](#):
> >
> > I was able to make the mesh somewhat usable by using [ParaView](https://www.paraview.org/)’s “Clean to grid” filter followed by “Extract surface”.
> 
> I will try if this works on the single tree object.
> 
> EDIT: I used “Clean to grid” filter followed by “Extract surface” and generated [this file](https://drive.google.com/file/d/1ILuFBIT5dNrxu0JQUcKDuK0uXiz8exYD/view?usp=sharing)  
> The endpoints weren’t detected for this too

As I wrote above, you need to split the forest and process each tree separately. There is a problem also with self-intersections. Fortunately, you don’t need any of this, as you can already get the tree from the XML file.

* * *

Since you already have a clear definition of the vessel tree in the XML file, you don’t need to use VMTK (which would provide end result very similar to the information in the XML file). I don’t think there is anything more I could help you with. You should be able to do the rest of the analysis by yourself, using various Python packages.

---

<div class="post-metadata">

### Author: ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)
#### Post date: [September 28, 2020, 1:55pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/7 "2020-09-28T13:55:47Z")

</div>

> [@lassoan](#):
>
> Having a tree in XML makes things very simple. Centerline length computation is trivial (sum of Euclidean distances between points that make up a branch).

Thank you, this helps a lot. May I know how the diameter can be computed?

---

<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: [September 28, 2020, 2:00pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/8 "2020-09-28T14:00:42Z")

</div>

> [@Deepa](#):
>
> May I know how the diameter can be computed?

As you can see in the XML file, vessel diameter is available for each point:

```xml
...
<point x="124.54" y="-421.36" z="-16.00" d="2.94"/>
...
`
```

---

<div class="post-metadata">

### Author: ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)
#### Post date: [September 28, 2020, 2:08pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/9 "2020-09-28T14:08:09Z")

</div>

Hi @lassoan Yes, I mean to ask if it would be right to simply compute the average diameter, using the diameter of each point, for finding out the diameter of a branch.

I had tried this before and the values were different. So I am not sure what’s right approach

---

<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: [September 28, 2020, 3:02pm UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/10 "2020-09-28T15:02:25Z")

</div>

This decision is up to you, whatever you find the most appropriate for your application.

---

<div class="post-metadata">

### Author: ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)
#### Post date: [October 2, 2020, 6:17am UTC](https://discourse.slicer.org/t/problem-in-extracting-centerlines/13551/12 "2020-10-02T06:17:23Z")

</div>

This case is going hopeless 🥱
