2D image on one slice

I would like to display a 2D image stored in a 3D numpy array (RGB image) only in one of the slices (for example the Red slice).

img = np.zeros((50,50,3))
img[10:40,20:30, 0] = 200  # saturate a part of the first channel
new_volume_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")
slicer.util.updateVolumeFromArray(new_volume_node, img)

With the code above each dimension of the array is connected to one of the slices (1st dimension to Red, 2nd to Green, 3rd to Yellow). Is there a way to display the whole image to one slice?

To display an RGB volume, you need to create a vtkMRMLVectorVolumeNode and array dimensions must be [dimZ, dimY, dimX, 3].

1 Like