# Different color in slices and 3D view

**URL:** <https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133>\
**Category:** Support\
**Created:** [February 23, 2022, 4:14pm UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133 "2022-02-23T16:14:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [February 23, 2022, 4:14pm UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133/1 "2022-02-23T16:14:31Z")

</div>

Hi all,

Is it posible to use different colors for the same segment (one for the slices and one for the 3D view)?

Thanks,

---

<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:** [February 24, 2022, 7:13am UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133/2 "2022-02-24T07:13:50Z")

</div>

There are several ways to achieve showing the same segmentation with different colors in different views.

- Option A: If you don’t want to do any Python scripting then you need to clone the segmentation, drag-and-drop a different node in the slice and the 3D view and change the color of one of the nodes.
- Option B: Create a new segmentation display node, add it as a display node to the segmentation node (the segmentation will have two display nodes), set the override color for the segment, and set the view node ID of the 3D view (to make this secondary display node only show the segmentation in the 3D view).

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [February 25, 2022, 9:45am UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133/3 "2022-02-25T09:45:43Z")

</div>

> [@lassoan](#):
>
> and change the color of one of the nodes

I tryied the first option. I can see the segmentations in different colors but I cannot edit both at the same time. That is, I change the segmentation in slice view but the change is not in 3D view. I thought that the cloned segmentation would be modified aswell.

Am I doing something wrong or it is not possible to edit the cloned segmentation at the same time?

Thanks

---

<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:** [February 25, 2022, 2:59pm UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133/4 "2022-02-25T14:59:02Z")

</div>

Option A is simple but changes are not automatically applied. You need Option B if you keep changing the segmentation.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [February 28, 2022, 12:01pm UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133/5 "2022-02-28T12:01:53Z")

</div>

> [@lassoan](#):
>
> Create a new segmentation display node, add it as a display node to the segmentation node (the segmentation will have two display nodes), set the override color for the segment, and set the view node ID of the 3D view (to make this secondary display node only show the segmentation in the 3D view).

Now it works!  
The code i have used is:

```auto
# Create a new segmentation display node
slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationDisplayNode")

# Add it as a display node to the segmentation node
segmentationNode.AddAndObserveDisplayNodeID(displayNode_copy.GetID())

# Set the override color for the segment
segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName("coronary")
displayNode_copy.SetSegmentOverrideColor(segmentID, 1, 0.7, 0)
displayNode_copy.SetVisibility2D(0)

# Set the view node ID of the 3D view
viewNode_new = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLViewNode")
displayNode_copy.SetViewNodeIDs(viewNode_new)
slicer.app.layoutManager().threeDWidget(0).setMRMLViewNode(viewNode_new)

```

---

<div class="post-metadata">

**Author:** ![Fokatu](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@Fokatu](https://discourse.slicer.org/u/Fokatu)\
**Post date:** [December 16, 2023, 12:43pm UTC](https://discourse.slicer.org/t/different-color-in-slices-and-3d-view/22133/6 "2023-12-16T12:43:12Z")

</div>

Hi Iassoan,  
Could you please help me check the code below? I want to show the data in both Red and Green view, with different displaynode, such that I can change the display seperately. But it does not work.

```auto
import numpy as np
x = np.random.randn(512, 512)
volumeNode = slicer.mrmlScene.AddNewNodeByClassWithID("vtkMRMLScalarVolumeNode", "ScanData", "vtkMRMLScalarVolumeNodeScanData")
slicer.util.updateVolumeFromArray(volumeNode, x)

d1 = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeDisplayNode")
d2 = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeDisplayNode")

volumeNode.AddAndObserveDisplayNodeID(d1.GetID())
volumeNode.AddAndObserveDisplayNodeID(d2.GetID())

v1 = slicer.util.getNode("Red Display")
v2 = slicer.util.getNode("Green Display")
d1.SetViewNodeIDs(v1)
d2.SetViewNodeIDs(v2)

```
