Get label map node from segmentation node

segmentation
#1

Hello!

Is there a way to create a label map node from a segmentation node? I know I can go the other way (from a label map to a segmentation), but I can’t seem to find a way to do the opposite. If this is not possible is there a way to at least get the array underlying the segmentation node? I know I can get an oriented image data, but if I do slicer.util.array on the oriented image data, nothing is returned.

Thanks!

(Csaba Pinter) #2

Answered in

You can also reach this function (i.e. Segmentations module import/export) from the Data module (right-click the segmentation), and in Segment Editor as an option for the Segmentations button.

#3

Awesome! Do you know how I might do this through the python code?

Found it:

slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode()

#4

Do you know what the inputs for this function is or where the documentation is for the segments?

slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode()

(Csaba Pinter) #5

These are the available signatures

A few examples of usage

#6

Are there examples in python?

(Andras Lasso) #7

You can always use help() function in Python to get documentation, for example:
help(slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode)

Example where it is used: https://github.com/Slicer/Slicer/blob/master/Utilities/Templates/Modules/ScriptedSegmentEditorEffect/SegmentEditorTemplateKeyLib/SegmentEditorEffect.py#L97

To create a custom Segment Editor effect, use ExtensionWizard module and choose ScriptedSegmentEditorEffect module template. It creates a fully functional effect that uses SimpleITK and you just have to replace the core of it to do what you need.

(Csaba Pinter) #8

@snvl The first two results in the search that was the second link in my post above are python examples.