# Retaining the color of the 2d image used for Volume Rendering.

**URL:** https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230
**Category:** Support
**Created:** [February 22, 2021, 4:19pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230 "2021-02-22T16:19:49Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Saptarshi\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/saptarshi_paul/32/3054_2.png) [@Saptarshi\_Paul](https://discourse.vtk.org/u/Saptarshi_Paul)
#### Post date: [February 22, 2021, 4:19pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/1 "2021-02-22T16:19:50Z")

</div>

Hello Everyone:

I am very new to volume rendering, and I was able to render a 3d Volume using stack of 2D images in png format. The resultant 3dVolume is in grey scale, but I want the color of the volume to be same as the image. How should I be able to acheive it? Any help or guidance is appreciated.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [February 22, 2021, 4:27pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/2 "2021-02-22T16:27:42Z")

</div>

Welcome to VTK, @Saptarshi_Paul!

In your mapper (`vtkVolumeMapper`?), invoke `SetColorModeToDirectScalars()`. That should avoid the mapping through the gray scale color map.

---

<div class="post-metadata">

### Author: ![Saptarshi\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/saptarshi_paul/32/3054_2.png) [@Saptarshi\_Paul](https://discourse.vtk.org/u/Saptarshi_Paul)
#### Post date: [February 22, 2021, 5:04pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/3 "2021-02-22T17:04:17Z")

</div>

Hello Cory,

Thank you so much for your help. I am using  
volumeMapper = vtk.vtkOpenGLGPUVolumeRayCastMapper(), so how will I be able to invoke SetColorModeToDirectScalars(). I will really appreciate if you can guide me through.

Best Regards

---

<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: [February 22, 2021, 5:44pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/4 "2021-02-22T17:44:03Z")

</div>

For volume rendering, you can use [vtkVolumeProperty::SetIndependentComponents()](https://vtk.org/doc/nightly/html/classvtkVolumeProperty.html#a2534a6dc500be42c9a842d405c4ee0bb).

---

<div class="post-metadata">

### Author: ![Saptarshi\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/saptarshi_paul/32/3054_2.png) [@Saptarshi\_Paul](https://discourse.vtk.org/u/Saptarshi_Paul)
#### Post date: [February 22, 2021, 5:49pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/5 "2021-02-22T17:49:44Z")

</div>

Hello Andras,

I hope you are doing well. I have already set the SetIndependentComponents(). But it still produces the resultant 3dVolume in grey scale.

---

<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: [February 22, 2021, 5:52pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/6 "2021-02-22T17:52:54Z")

</div>

Probably you don’t have an alpha channel. See details in this topic: [Colored Volume from Tiffstack/MultiImageTiff](https://discourse.vtk.org/t/colored-volume-from-tiffstack-multiimagetiff/4909/7)

---

<div class="post-metadata">

### Author: ![Saptarshi\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/saptarshi_paul/32/3054_2.png) [@Saptarshi\_Paul](https://discourse.vtk.org/u/Saptarshi_Paul)
#### Post date: [February 22, 2021, 6:15pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/7 "2021-02-22T18:15:28Z")

</div>

Thank you so much Andras, it worked.  
I really appreciate your help.

Best Regards

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [February 22, 2021, 6:16pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/8 "2021-02-22T18:16:25Z")

</div>

Ah, sorry. I remembered the class hierarchy incorrectly.

---

<div class="post-metadata">

### Author: ![Saptarshi\_Paul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/saptarshi_paul/32/3054_2.png) [@Saptarshi\_Paul](https://discourse.vtk.org/u/Saptarshi_Paul)
#### Post date: [February 22, 2021, 6:25pm UTC](https://discourse.vtk.org/t/retaining-the-color-of-the-2d-image-used-for-volume-rendering/5230/9 "2021-02-22T18:25:34Z")

</div>

Thank you Cory, I really appreciate your help.

Best Regards
