Extract centerline Python scripting


I am trying to automatize the process of extracting a centerline.
I want an automatic configuration that looks like:

I have some lines of code based on:
import ExtractCenterline

ec = ExtractCenterline.ExtractCenterlineLogic()
s = segmentationNode.GetSegmentation()
ss = s.GetSegment(s.GetSegmentIdBySegmentName(“aortaCompleta”)).GetRepresentation(‘Closed surface’)
fids = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLMarkupsFiducialNode”)
centerlinePolyData,voronoiDiagramPolyData = ec.extractCenterline(ss, fids)
But I can’t find the centerline after this

I also tryied to modify the ParameterNode
ec.getParameterNode().SetParameter(“InputSurface”, segmentID)
but I don’t know how to see changes on GUI and modify the “Tree” section.

Thanks :slight_smile:

You seem to mix up things here.

\1. If you wish to work with the logic class of ‘ExtractCenterline’ module, this post is very instructive. The logic class won’t modify the UI in itself.

\2. If you wish to work with the ‘ExtractCenterline’ module’s GUI, you can access all UI widgets this way :

ecWidgetRepresentation = slicer.modules.extractcenterline.widgetRepresentation()
ecUI = ecWidgetRepresentation.ui

For example, to get a handle to the output curve combobox, you would use ecUI.outputCenterlineCurveSelector.

1 Like


This gives me an error

ecWidgetRepresentation = slicer.modules.extractcenterline.widgetRepresentation()
ecUI = ecWidgetRepresentation.ui


But I tryied with this and seems to work fine

ecUI = slicer.modules.ExtractCenterlineWidget.ui

However I don’t know how to change options. Could you give me an example of how to change (for instance) the input surface? I am quite noob with slicer.


You’re right, it should be :
ecUI = ecWidgetRepresentation.self().ui

As for slicer.modules.ExtractCenterlineWidget.ui, slicer.modules.ExtractCenterlineWidget is available only if you have shown the ‘ExtractCenterline’ module once, or if you have run slicer.modules.extractcenterline.widgetRepresentation() once. That is, the widget representation needs to be created.

segmentation = slicer.util.getNode("Segmentation")

In a real application, you won’t use getNode() of course. Either you create a node, or you get it from a UI widget following its API.