# Display 3D image in RGB

**URL:** https://discourse.vtk.org/t/display-3d-image-in-rgb/7122
**Category:** Support
**Created:** [November 9, 2021, 4:15pm UTC](https://discourse.vtk.org/t/display-3d-image-in-rgb/7122 "2021-11-09T16:15:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Luis\_Carlos\_Carneiro](https://discourse.vtk.org/user_avatar/discourse.vtk.org/luis_carlos_carneiro/32/1360_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.vtk.org/u/Luis_Carlos_Carneiro)
#### Post date: [November 9, 2021, 4:15pm UTC](https://discourse.vtk.org/t/display-3d-image-in-rgb/7122/1 "2021-11-09T16:15:42Z")

</div>

Dear All,

I want to display a 3D image in RGB. What is missing in the following code?

```
    self.image_3d = vtk.vtkImageData()
    self.image_3d.SetDimensions(dim5)
    self.image_3d.SetSpacing(scale5)
    points = self.image_3d.GetPointData()
    points.SetScalars(numpy_support.numpy_to_vtk(
        np.zeros((dim5[0]*dim5[1]*dim5[2],3), dtype=np.uint8)))
    #Fill image with data
    self.volumeMapper_3d = vtk.vtkOpenGLGPUVolumeRayCastMapper()
    self.volumeMapper_3d.SetInputData(self.image_3d)
    self.volume_3d = vtk.vtkVolume()
    self.volume_3d.PickableOff()
    self.volume_3d.SetMapper(self.volumeMapper_3d)
    self.volume_3d.SetUserTransform(self.transform)
    renderer.AddVolume(self.volume_3d)

```

Thanks,

Luís Gonçalves

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [November 9, 2021, 7:24pm UTC](https://discourse.vtk.org/t/display-3d-image-in-rgb/7122/2 "2021-11-09T19:24:12Z")

</div>

You need to tell VTK how to interpret scalar components using [vtkVolumeProperty::SetIndependentComponents](https://vtk.org/doc/nightly/html/classvtkVolumeProperty.html#a2534a6dc500be42c9a842d405c4ee0bb).

As a side note: avoid instantiating vtkOpenGLGPUVolumeRayCastMapper directly but instead use vtkGPUVolumeRayCastMapper and let VTK decide what specific implementation class to use.
