# Adding colors to a volume (painting)

**URL:** <https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191>\
**Category:** Development\
**Tags:** extensions-manager\
**Created:** [September 26, 2018, 9:20am UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191 "2018-09-26T09:20:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [September 26, 2018, 9:20am UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/1 "2018-09-26T09:20:14Z")

</div>

Hi all,

I have a question regarding the editing/ painting of volumes. I would like to craft a color-version of my CT scan and ideally, I would like to follow the following workflow:

1. Load a scan (grayscale)
2. Load a colortable to translate the grayscale values to colors
3. Create a new colorvolume from scan+colortable
4. Edit the colors in the colorvolume using a paint tool.

I experimented a bit with the Volume and Editor module. But I can not get it to work. I can create an empty label node, but that one is not filled with colors coming from the colortable I selected in Volumes. In the Editor module itself I am only able to select a couple of predefined colors, there is no colorpicker.

Does anybody have any hits or a different approach to the coloring of scans?

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [September 26, 2018, 10:26am UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/2 "2018-09-26T10:26:22Z")

</div>

> [@Using GLSL post-process (2D) pixel shader with Slicer](https://discourse.slicer.org/t/using-glsl-post-process-2d-pixel-shader-with-slicer/1789/5):
>
> Here’s the other GLSL code @Davide_Punzo mentioned. It’s less coupled to the vtk rendering process so it can make it simpler to do generic algorithms. At some point I plan to revisit this and see how it compares to the shader options recently added to VTK core and see if it’s still needed.

---

<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:** [September 26, 2018, 2:26pm UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/3 "2018-09-26T14:26:57Z")

</div>

You can easily achieve all this using Segment Editor module. Threshold effect can be used to assign segments (colored regions) to a grayscale range. If you have many segments then you can automate segment creation by 10-20 lines of Python code - see “skin surface extraction” example in [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script).

---

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [September 27, 2018, 10:37am UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/4 "2018-09-27T10:37:48Z")

</div>

Sound worth a try!

Yesterday I thought of another approach: what about iterating the voxel array and sampling the displayNode colorMapper to get a color value. Then for each voxel I can write its colorvalue to a labelmap or some other format that can store rgb values?

---

<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:** [September 27, 2018, 11:43am UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/5 "2018-09-27T11:43:58Z")

</div>

What data would you like to have at the end? What would you use it for?

---

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [September 27, 2018, 12:14pm UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/6 "2018-09-27T12:14:45Z")

</div>

In the end I would like to have a color volume that represents color, not grayscale. I would like to use it as a 3DTexture for rendering in OpenGL or Direct3D.

---

<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:** [September 27, 2018, 12:21pm UTC](https://discourse.slicer.org/t/adding-colors-to-a-volume-painting/4191/7 "2018-09-27T12:21:16Z")

</div>

For this purpose, a color lookup table is the appropriate solution. It is much more efficient in term of storage space and rendering speed and much more flexible (you can change color/opacity on-the-fly).
