# How to obtain the complete center lines using VMTK?

**URL:** <https://discourse.slicer.org/t/how-to-obtain-the-complete-center-lines-using-vmtk/14068>\
**Category:** VMTK\
**Tags:** centerlines\
**Created:** [October 16, 2020, 3:57am UTC](https://discourse.slicer.org/t/how-to-obtain-the-complete-center-lines-using-vmtk/14068 "2020-10-16T03:57:43Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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 20, 2020, 3:26am UTC](https://discourse.slicer.org/t/how-to-obtain-the-complete-center-lines-using-vmtk/14068/4 "2020-10-20T03:26:22Z")

</div>

Summary: I’ve tested your data set and everything worked well if I made branches a bit thicker. VMTK’s centerline extraction cannot seem to be able to track down endpoints though narrow, pointy tips.

Details:

I’ve imported the mask into a segmentation node Slicer and ran it through VMTK extension’s Extract centerline module:

```python
# Load mask into labelmap volume
import numpy as np
d = np.load(r'c:\Users\andra\OneDrive\Projects\SlicerTesting5\20201019-AirwayNetworkAnalysis\PA000019.npz', allow_pickle=True)
volumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.util.updateVolumeFromArray(volumeNode, d['isoMask'])

# Convert labelmap volume to segmentation node
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
slicer.vtkSlicerSegmentationsModuleLogic.ImportLabelmapToSegmentationNode(volumeNode, segmentationNode)
segmentationNode.CreateClosedSurfaceRepresentation()

```

Automatic endpoint detection worked well:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/a/daec62c6077c4a85c5c72e5a14a3f84f8b6cd6d8.jpeg)

Centerline detection did not succeed - path was not found to endpoints that were connected to the bronchial tree with a narrow branch/sharp tip:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/1/51f118d7a898d3459b3865bcc799110d77b5853b.png)

I’ve fixed the narrow branches by oversampling the image by a factor of 2x (subdivide every voxel by 2x2x2) and applying Margin effect in Segment editor:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/c/0cd823e7091dbab151455d03976b96ef0cb85a39.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/5/b55b2742cccc4268bb6e8ba81f7a295e8e45e47b.png)

After this, centerline extraction worked flawlessly:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/8/3893e6198629048484eab72e5fcf9c3618416471.png)

Original mask (in interactive web viewer):

https://kitware.github.io/vtk-js/examples/OBJViewer/OBJViewer.html?fileURL=https://dl.dropboxusercontent.com/s/hbal6lgttrx6ekq/Original.zip

Dilated mask (in interactive web viewer):

https://kitware.github.io/vtk-js/examples/OBJViewer/OBJViewer.html?fileURL=https://dl.dropboxusercontent.com/s/yo5v2usrogv2eu1/Dilated.zip

---

_[View the full topic](https://discourse.slicer.org/t/how-to-obtain-the-complete-center-lines-using-vmtk/14068)._
