# Creating a sicer module: Overlap RGB arrays

**URL:** <https://discourse.slicer.org/t/creating-a-sicer-module-overlap-rgb-arrays/6182>\
**Category:** Support\
**Tags:** python\
**Created:** [March 18, 2019, 4:15am UTC](https://discourse.slicer.org/t/creating-a-sicer-module-overlap-rgb-arrays/6182 "2019-03-18T04:15:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![laura.gelcano](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@laura.gelcano](https://discourse.slicer.org/u/laura.gelcano)\
**Post date:** [March 18, 2019, 4:15am UTC](https://discourse.slicer.org/t/creating-a-sicer-module-overlap-rgb-arrays/6182/1 "2019-03-18T04:15:14Z")

</div>

Operating system:Windows  
Slicer version: 4.8.1

Hi all,  
I am creating a module using python.

First, I have an image as inputVolume, which I have converted into an array to know some information such as dimensions:

nodeInput = self.inputSelector.currentNode ()  
volume = slicer.util.arrayFromVolume(nodeInput)  
numGrids = len(volume)

Second, I created an RGB array, initialized as:

image = np.zeros ([256,256,4], dtype =np.uint8);  
GridsImage = [image] \* numGrids;

As a result, I have 3 numpy RGB arrays: GridImage [0], GridImage [1] and GridImage [2]. Each array is completed by reading from a .txt file.

Now I want to overlap, the RGB arrays in the input image as the output volume. Any help or sugggestion?

How can I overlap a numpy RGB array into a input volume?

Thanks you in advance

---

<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:** [March 18, 2019, 4:57am UTC](https://discourse.slicer.org/t/creating-a-sicer-module-overlap-rgb-arrays/6182/2 "2019-03-18T04:57:36Z")

</div>

In slice views, you can overlay two scalar volumes by choosing one of them as foreground and the other as background volume. From Python, you can use `slicer.util.setSliceViewerLayers()` method to choose volumes and opacity of the overlaid volume.

To create a RGB color volume from a numpy array, use `slicer.util.updateVolumeFromArray` like this:

```
volumeNodeRGB = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLVectorVolumeNode")
import numpy as np
voxels = np.random.rand(20,30,40,3)
slicer.util.updateVolumeFromArray(volumeNodeRGB, voxels)
slicer.util.setSliceViewerLayers(background=volumeNodeRGB, fit=True)
```

---

<div class="post-metadata">

**Author:** ![laura.gelcano](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@laura.gelcano](https://discourse.slicer.org/u/laura.gelcano)\
**Post date:** [March 19, 2019, 8:42pm UTC](https://discourse.slicer.org/t/creating-a-sicer-module-overlap-rgb-arrays/6182/3 "2019-03-19T20:42:41Z")

</div>

Thanks for answering.

I’m trying other alternatives, since I have problems overlaying both volumes in the correct position.

Also, fit = True argument is not defined in my program version.

I’m trying to create a color image of the arrayRGB and overlay it with the input volume.

I have tried with this:

voxelsRGB = np.zeros ([256, 256, 1, 4], dtype = np.uint8)  
nodeOutput = self.outputSelector.currentNode ()  
sitkImageOutput = sitk.GetImageFromArray (voxelsRGB)  
volumeNode = sitkUtils.PushVolumeToSlicer (sitkImageOutput, None)  
slicer.util.setSliceViewerLayers (background = volumeNode)  
sitkUtils.PushVolumeToSlicer (sitkImageOutput, outputVolumeNode)  
nodeOutput.SetOrigin (nodeInput.GetOrigin ())  
nodeOutput.SetSpacing (nodeInput.GetSpacing ())  
slicer.util.updateVolumeFromArray (nodeOutput, voxelsRGB)

However, I can’t import stikUtils library.

What I actually want to do is to read a set of coordinates from a text file and paint the corresponding pixel in red, blue or green. The color of the pixel is read from another text file.  
Is there any other way to color a specific pixel?

Any help is appreciated

---

<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:** [March 19, 2019, 9:09pm UTC](https://discourse.slicer.org/t/creating-a-sicer-module-overlap-rgb-arrays/6182/4 "2019-03-19T21:09:38Z")

</div>

> [@laura.gelcano](#):
>
> Also, fit = True argument is not defined in my program version.

Please use latest stable version (4.10.1).

> [@laura.gelcano](#):
>
> sitkUtils.PushVolumeToSlicer

This is deprecated. Please use [slicer.util](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#module-slicer.util) helper functions instead.

> [@laura.gelcano](#):
>
> What I actually want to do is to read a set of coordinates from a text file and paint the corresponding pixel in red, blue or green.

This sounds terribly inefficient. How many points do you have? Do you really want to color single voxels like this or actually you would like to place a colored markers at each of the listed positions?
