# Change segment color and opacity

**URL:** <https://discourse.slicer.org/t/change-segment-color-and-opacity/7855>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [August 2, 2019, 6:06pm UTC](https://discourse.slicer.org/t/change-segment-color-and-opacity/7855 "2019-08-02T18:06:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazlynn21100](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jazlynn21100](https://discourse.slicer.org/u/jazlynn21100)\
**Post date:** [August 2, 2019, 6:06pm UTC](https://discourse.slicer.org/t/change-segment-color-and-opacity/7855/1 "2019-08-02T18:06:09Z")

</div>

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?

---

<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:** [August 2, 2019, 9:33pm UTC](https://discourse.slicer.org/t/change-segment-color-and-opacity/7855/2 "2019-08-02T21:33:49Z")

</div>

You can adjust most display properties by modifying the segmentation’s [display node](https://apidocs.slicer.org/master/classvtkMRMLSegmentationDisplayNode.html). 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.

```python
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

```

---

<div class="post-metadata">

**Author:** ![CB1](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cb1/32/6511_2.png) [@CB1](https://discourse.slicer.org/u/CB1)\
**Post date:** [September 23, 2020, 2:00pm UTC](https://discourse.slicer.org/t/change-segment-color-and-opacity/7855/3 "2020-09-23T14:00:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 23, 2020, 2:04pm UTC](https://discourse.slicer.org/t/change-segment-color-and-opacity/7855/4 "2020-09-23T14:04:44Z")

</div>

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!
