Change segment color and opacity

Ok 2 ,more questions and I promise I’m done

If you want to set a segmentation’s color, my assumption is that it would be an addition to this line:

addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment(“brain”)

to the AddEmptySegment portion; so you have #faf9e3 as the color HTML, what would the line change to to add color?

2nd question:
If you wanted to change the opacity of the segmentations, that’s in the Segmentations module, so would you have to load that model in order to change the opacity?

You can adjust most display properties by modifying the segmentation’s display node. The only exception is the segment color, which can be overridden in the display node but recommended to be set in the segmentation node instead.

segmentationNode=slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLSegmentationNode")
segmentationDisplayNode=segmentationNode.GetDisplayNode()
segmentation=segmentationNode.GetSegmentation()

# Change overall segmentation display properties
segmentationDisplayNode.SetOpacity3D(0.5)

# Change one segment display properties
segmentId = segmentation.GetSegmentIdBySegmentName("Segment_1")
segmentationDisplayNode.SetSegmentOpacity2DOutline(segmentId, 0.0)
segmentation.GetSegment(segmentId).SetColor(1,0,0)  # color should be set in segmentation node
1 Like

I’m trying to change the opacity of everything but a small range of intensities on my model. Can I do that with this method? I’m completely new to slicer.

Please create a new topic and in that give us more information. Describe exactly what you’d like to achieve, what kind of data you have, what tools you want to use, etc. Thanks!