# Improving vmtk-centerline detection

**URL:** <https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935>\
**Category:** Support\
**Tags:** vmtk, vmtk-centerline\
**Created:** [September 27, 2023, 2:55pm UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935 "2023-09-27T14:55:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![b\_gop](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/b_gop/32/67116_2.png) [@b\_gop](https://discourse.slicer.org/u/b_gop)\
**Post date:** [September 27, 2023, 2:55pm UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/1 "2023-09-27T14:55:56Z")

</div>

I am trying to get the centerline for a very intricate tree-like structure. While the centerline computation gets most of the structure, there are still branches that it does not cover despite there being endpoints on those branches. Are there any ways I can improve the coverge?

I went through [http://lantiga.github.com/media/AntigaPhDThesis.pdf](http://lantiga.github.com/media/AntigaPhDThesis.pdf) and I get that:

1. Voronoi smoothing can help with increasing branching coverage
2. It may help to change the sphere radius that has been hardcoded (r= k\*d)

But I am not sure how I can tune these parameters through the 3DSlicer UI.

Would anyone have any suggestions?

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:** [September 28, 2023, 3:18am UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/2 "2023-09-28T03:18:55Z")

</div>

Do you use network extraction or centerline extraction?

If you use centerline extraction, you may need to move the automatically detected endpoints a bit closer (further up towards the parent branch) to make sure a path can be found to it.

You can enable “Developer mode” in application settings and then click on the “Edit” button in the “Extract Centerline” module GUI and then you can edit all the parameters.

Voronoi smoothing is not available since VTK-9.2 introduced some backward-incompatible changes, but it should not matter, as it generally just barely improved connectivity if at all.

---

<div class="post-metadata">

**Author:** ![b\_gop](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/b_gop/32/67116_2.png) [@b\_gop](https://discourse.slicer.org/u/b_gop)\
**Post date:** [September 28, 2023, 3:29pm UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/3 "2023-09-28T15:29:39Z")

</div>

I use centerline extraction.

Okay, right.

As I am working on a big volume, it might not be possible to move all of the points manually. Can you suggest any methods to train a network to predict the endpoints better?

Thank you for your help!

---

<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, 2023, 3:35pm UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/4 "2023-09-28T15:35:09Z")

</div>

It should be possible to slightly adjust the automatic endpoint detection function to snap to the closest Voronoi surface point that has sufficiently large associated radius. For the implementation you can use VTK threshold filter to remove points of the Voronoi surface that has small associated radius, then use a locator to find closest point on this reduced surface. It would probably not take more than 15-20 lines of Python code in total. The [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html) and Bing Chat or ChatGPT should be able to give you all the code snippets you need but if you get stuck then you can ask us here.

---

<div class="post-metadata">

**Author:** ![b\_gop](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/b_gop/32/67116_2.png) [@b\_gop](https://discourse.slicer.org/u/b_gop)\
**Post date:** [October 2, 2023, 11:53am UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/5 "2023-10-02T11:53:04Z")

</div>

Thank you for your response!

A couple of questions:

1. Wouldn’t removing points with small associated radius also remove connections of thin branch points?

2. Should these new points be used along with the automatic detection?

3. Do I simply use these new points for centerline detection or do is there any other intermediate step? I tried using just the new endpoints for the detection and also the new points combined with the automatically detected points. Each time there was barely a centerline formed and I received this error message on the console:

[VTK] vtkvmtkSteepestDescentLineTracer (0000017EAB6FA3B0): Can’t find a steepest descent edge. Target not reached.  
[VTK] Warning: In vtkvmtkSteepestDescentLineTracer.cxx, line 240  
[VTK] vtkvmtkSteepestDescentLineTracer (0000017EAB6FA3B0): Degenerate descent detected. Target not reached.  
[VTK] Warning: In vtkvmtkSteepestDescentLineTracer.cxx, line 240

---

<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 2, 2023, 1:49pm UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/6 "2023-10-02T13:49:19Z")

</div>

> [@b\_gop](#):
>
> Wouldn’t removing points with small associated radius also remove connections of thin branch points?

It would not remove any connections, it would only make the centerline shorter by a fraction of a millimeter.

> [@b\_gop](#):
>
> Should these new points be used along with the automatic detection?

You would add this as a preprocessing step in centerline extraction: you would not use the raw input that the user provides (that may come from manual specification or automatic endpoint detection) but first you would snap the points to the Voronoi diagram.

> [@b\_gop](#):
>
> I tried using just the new endpoints for the detection and also the new points combined with the automatically detected points. Each time there was barely a centerline formed

There might be a bug in the implementation. Could you please send a link to your github repository/branch where you added this?

---

<div class="post-metadata">

**Author:** ![b\_gop](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/b_gop/32/67116_2.png) [@b\_gop](https://discourse.slicer.org/u/b_gop)\
**Post date:** [October 3, 2023, 11:44am UTC](https://discourse.slicer.org/t/improving-vmtk-centerline-detection/31935/7 "2023-10-03T11:44:09Z")

</div>

You can find the implementation here: [GitHub - bhavika-g/vmtk](https://github.com/bhavika-g/vmtk.git)

I misunderstood your suggestion earlier so I have made edits now, but the application/code seems to freeze for a very long time (24+ hours) at the “markupsNode.AddControlPoint(point[0], point[1], point[2])” line.
