Accessing Segmentation Layer Visibility By View

Hi All,

I’m curious if there is a way to show particular segmentation nodes on each of four different views in a two over two layout programmatically. An example of doing this for background volumes would be as follows:

volumes_of_interest = [pre_T1, pre_ADC, post_T1, post_ADC]

viewNodes = slicer.mrmlScene.getNodesByClass('vtkMRMLSliceCompositeNode')
for i,viewNode in enumerate(viewNodes):


In our use case we make unique segmentations on two different MRI sequences before and after an intervention. Being able to view and touch-up all four segmentations would be helpful.

I understand that Segmentations play by different rules. I tried exploring SetDisplayVisibility, but it seems to only act globally on all views.

Any suggestions are much appreciated.



You can add multiple segmentation display nodes to have one for each view. Then set view node ID and visibility in each display node.

What do you mean by specifically by a segmentation display node?

In the API vtkMRMLDisplayableNode doesn’t seem have a view node ID attribute and vtkMRMLSegmentationNode doesn’t seem to have a visibility attribute.

Create one using slicer.mrmlScene.AddNewNodeByClass and add it to the segmentation node using its AddAndObserveDisplayNodeID method.

These are display node methods.


# Get segmentation node, for the rest, we assume that there are 3 segments, with default names/ids

# Get display node that is used by default for all views

# Add one more display node

# Display node 1: show only in Red slice view, show only segment 3

# Display node 2: show only in Yellow nad Green slice views, show only segment 1
segmentationDisplayNode2.SetViewNodeIDs(['vtkMRMLSliceNodeYellow', 'vtkMRMLSliceNodeGreen'])
1 Like

Hi Andras,

This is really helpful! Thanks so much for providing the examples.

I also found this DisplayNode method that similarly achieves only showing segmentations in select views.

segmentationDisplayNode = segmentNode.GetDisplayNode()    
sliceNode = 'vtkMRMLSliceNodeRed'
1 Like