# Automate extract centerline with unconnected segment

**URL:** <https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851>\
**Category:** Development\
**Created:** [October 23, 2022, 2:09pm UTC](https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851 "2022-10-23T14:09:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbr](https://avatars.discourse-cdn.com/v4/letter/h/8edcca/32.png) [@hbr](https://discourse.slicer.org/u/hbr)\
**Post date:** [October 23, 2022, 2:09pm UTC](https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851/1 "2022-10-23T14:09:03Z")

</div>

Hi.

I wanna extract center line of a segmentation that is unconnected. I have a script that do it automatically but when get this segmentation just extract center line partly not all.

 ![Screenshot from 2022-10-23 17-41-40](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/9/69dbf934e54c994af70997f94c5ac1ffeeef0c48.png)

Do anybody have a solution for it?

thanks

---

<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:** [October 24, 2022, 2:47am UTC](https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851/2 "2022-10-24T02:47:28Z")

</div>

For best results, it would be better to improve the segmentation so that there is no discontinuity in the vessel tree. If you find that too difficult to do it automatically then you can split the segments, detect centerline in each segment separately, and then create an automatic algorithm that merges centerlines.

---

<div class="post-metadata">

**Author:** ![hbr](https://avatars.discourse-cdn.com/v4/letter/h/8edcca/32.png) [@hbr](https://discourse.slicer.org/u/hbr)\
**Post date:** [October 24, 2022, 8:06am UTC](https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851/3 "2022-10-24T08:06:42Z")

</div>

thanks for response.

is there a method to get endpoints for hole sementation instead of partly like my example with unconnected segment?

thanks

---

<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:** [October 24, 2022, 11:22am UTC](https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851/4 "2022-10-24T11:22:36Z")

</div>

It would be straightforward to implent such algorithm, for example by splitting the polydata so that you have one connected component in each resulting polydata and process each polydata one by one. However, does not seem to be commonly needed and it would make the current implementation more complex, so I don’t think anyone would start working on this right now (until many small projects or one funded projects need this).

Fortunately, the Extract Centerline module is just a Python scripted module, if you have a little experience in Python and interested in learning a bit about VTK and VMTK libraries then you can add this feature. We can help you if you get stuck at any point.

---

<div class="post-metadata">

**Author:** ![hbr](https://avatars.discourse-cdn.com/v4/letter/h/8edcca/32.png) [@hbr](https://discourse.slicer.org/u/hbr)\
**Post date:** [October 24, 2022, 4:12pm UTC](https://discourse.slicer.org/t/automate-extract-centerline-with-unconnected-segment/25851/5 "2022-10-24T16:12:46Z")

</div>

thank you Andras.

i will try it and if i have any problems let you know to help.
