# Retain Image Color in Volume Rendering

**URL:** <https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294>\
**Category:** Support\
**Created:** [June 30, 2020, 12:27pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294 "2020-06-30T12:27:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [June 30, 2020, 12:27pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/1 "2020-06-30T12:27:25Z")

</div>

I am looking to create a 3D model of a stack of images, retaining the original image color. See the screenshot as a reference.

By creating a segmentation with a threshold of 22 - 255 I am able to select the desired part and create a model, however, then the color becomes the label color. I’d like to create the exact same 3D model, except with the original colors.

Is this possible?

I have already consulted this tread, yet the code suggested there gives me errors (if a trace is useful I can provide that)

> [@Merge colored images and show them as 1 volume](https://discourse.slicer.org/t/merge-colored-images-and-show-them-as-1-volume/6472/4):
>
> If you just want to visualize them with their original color, apply spatial transforms, etc. then you don’t need to convert to scalar volume. What would you like to do with the image?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/4/24372b67979821b2bea2adbef5a9e03be72ae8ec.jpeg)

P.s. I’ve had quite a few issues with 4.11 on Linux; 1. I can’t load saved files, as this crashes the program, 2. I can’t use “Surface smoothing”, as that crashes the application. (4.10 gives me even more issues)

```auto
SetConversionParameter: Conversion parameter 'Collapse labelmaps' not found in converter rules!

SetConversionParameter: Conversion parameter 'Joint smoothing' not found in converter rules!

error: [/home/tyler/Downloads/Slicer-4.10.2-linux-amd64/bin/SlicerApp-real] exit abnormally - Report the problem.

```

---

<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:** [June 30, 2020, 12:32pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/2 "2020-06-30T12:32:15Z")

</div>

If Slicer crashes then it is almost surely because you run out of memory. How large is your input image and how much physical RAM do you have and how much swap space have you configured?

Please also provide the trace for the error.

Have you tried it with the very latest Slicer Preview Release?

---

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [June 30, 2020, 12:59pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/3 "2020-06-30T12:59:26Z")

</div>

16GB of ram, no swap set up. Trace is here [https://pastebin.com/qr5U16MJ](https://pastebin.com/qr5U16MJ)

Memory usage goes up to 92% and then crashes.

Although that’s not my primary issue, do you have any clue whether original colored 3d models are possible?

---

<div class="post-metadata">

**Author:** ![rkikinis](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rkikinis/32/791_2.png) [@rkikinis](https://discourse.slicer.org/u/rkikinis)\
**Post date:** [June 30, 2020, 1:21pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/4 "2020-06-30T13:21:59Z")

</div>

Have you tried volume rendering? Slicer takes the LUT setting and window/level as a startpoint for the transfer function of the volume renderer

 ![Screen Shot 2020-06-30 at 9.21.49 AM.png](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/f/4fc077a565eb348e44bde74aedfac08fce949fd8.jpeg)

---

<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:** [June 30, 2020, 1:45pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/5 "2020-06-30T13:45:35Z")

</div>

Yes, you should be able to color a model’s surface using a color volume using latest Slicer Preview Release. I’ll double-check if it works as expected.

Memory usage at 92% means there is a high chance of running out of memory. If you configure a few ten GB of swap space then it should take care of it.

What is the size and d your data set? What is the scalar type? (these are shown in Volumes module Volume information section)

---

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [June 30, 2020, 3:24pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/6 "2020-06-30T15:24:21Z")

</div>

The first thing I tried was volume rendering, but then I just get a black box, so I’m wondering how I can cut out the black parts.

Scalar type is unsigned char, and 1.2gb of 388 1080x1080 tiff images

This is my dataset : [https://1drv.ms/u/s!AprYdPzSEdGHgpo5lgPqkwL-hQdi8g?e=xW1FPa](https://1drv.ms/u/s!AprYdPzSEdGHgpo5lgPqkwL-hQdi8g?e=xW1FPa)

---

<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:** [June 30, 2020, 3:37pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/7 "2020-06-30T15:37:31Z")

</div>

How did you create these images? Can you just export them as scalar volume? Then you could apply color mapping in Slicer, easily use volume rendering, etc. The problem really is that the color look-up is burnt into the image.

---

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [June 30, 2020, 3:53pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/8 "2020-06-30T15:53:04Z")

</div>

Ah hmm. I’m not sure, I didn’t create them. I’ll ask if that’s possible.

Is there any work around for these images?

---

<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:** [June 30, 2020, 4:01pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/9 "2020-06-30T16:01:59Z")

</div>

If the colors are result of color imaging there is not much to do (then you probably want to use the original color) but if they are result of applying a color map (color look-up table) then it would be better to get the original scalar images.

Anyway, color volume rendering should work, too, as described in this post: [Merge colored images and show them as 1 volume](https://discourse.slicer.org/t/merge-colored-images-and-show-them-as-1-volume/6472/6)

---

<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:** [June 30, 2020, 4:41pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/10 "2020-06-30T16:41:57Z")

</div>

I’ve downloaded your images and used this script to convert it to add an alpha channel and enable direct RGBA volume rendering (just copy-paste it into Slicer’s Python console after you loaded your data set):

```python
# Find loaded vector volume
colorVolume = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLVectorVolumeNode")

# Convert RGB image to RGBA
luminance = vtk.vtkImageLuminance()
luminance.SetInputConnection(colorVolume.GetImageDataConnection())
append=vtk.vtkImageAppendComponents()
append.AddInputConnection(colorVolume.GetImageDataConnection())
append.AddInputConnection(luminance.GetOutputPort())
append.Update()
colorVolume.SetAndObserveImageData(append.GetOutput())

# Enable volume rendering
volRenLogic = slicer.modules.volumerendering.logic()
displayNode = volRenLogic.CreateDefaultVolumeRenderingNodes(colorVolume)
displayNode.SetVisibility(True)
# Enable direct RGBA color mapping
displayNode.GetVolumePropertyNode().GetVolumeProperty().SetIndependentComponents(0)

```

After slightly adjusting scalar opacity mapping in Volume rendering module and changing background to black I got this beautiful rendering:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/b/2b6a99fe5cbd18821242f9986ee535590653a1fd.jpeg)

A video created by Screen Capture module:

[![](https://img.youtube.com/vi/o5I_XWkm1nk/maxresdefault.jpg "Color volume rendering") ](https://www.youtube.com/watch?v=o5I_XWkm1nk)

We plan to release Slicer5 soon and looking for nice images that could demonstrate capabilities of the application. Would you consider allowing this data set to be showcased as an image or video (with proper acknowledgments and reference to publication)?

---

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [June 30, 2020, 6:58pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/11 "2020-06-30T18:58:18Z")

</div>

Oh wow that looks really good, thanks!  
I’ll ask at work if they are fine with that, I’ll let you know 🙂

---

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [July 1, 2020, 2:15pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/12 "2020-07-01T14:15:51Z")

</div>

I’ve been able to recreate the Volume, which is really cool. Now I am looking to export it of some sort (with the end goal of creating more complex animations)

Therefore I tried to segment it as I read from all the other treads you can’t export a volume rendering, however, is it possible to retain the color of the model in the segmentation?

I have referenced your answers [here](https://discourse.slicer.org/t/merge-colored-images-and-show-them-as-1-volume/6472/6) , yet was unsuccessful in creating a mesh with colors, is it possible to do this with this software?

---

<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:** [July 1, 2020, 2:49pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/13 "2020-07-01T14:49:52Z")

</div>

Volume rendering is a display technique, which produces a 2D color picture. There is nothing else that could be “exported”. See more detailed description [here](https://discourse.slicer.org/t/save-volume-rendering-as-stl-file/524).

To display a volume like this, you need to use volume rendering. Blender can do everything, including volume rendering, but of course it is very complicated to achieve something like that is shown above. If you want to try it anyway then you can find some pointers [here](https://discourse.vtk.org/t/bvtknodes-photorealistic-rendering-of-vtk-data-in-blender/3268/16).

---

<div class="post-metadata">

**Author:** ![David\_Brouwer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_brouwer/32/7291_2.png) [@David\_Brouwer](https://discourse.slicer.org/u/David_Brouwer)\
**Post date:** [July 1, 2020, 3:39pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/14 "2020-07-01T15:39:47Z")

</div>

Thanks a lot for the info, it is greatly appreciated. The BVTKNodes link you provided looks very interesting. The result of the sample set you provided looks really nice.

I am looking to give it a shot. If doesn’t take too much time, with the programs mentioned being Paraview, the BVTKNodes plugin, and Blender itself, what would be the general workflow here?

---

<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:** [July 1, 2020, 5:25pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/15 "2020-07-01T17:25:57Z")

</div>

You should be able to load the volume directly into Blender and render it there.

---

<div class="post-metadata">

**Author:** ![tgterra](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tgterra](https://discourse.slicer.org/u/tgterra)\
**Post date:** [April 14, 2021, 1:10pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/16 "2021-04-14T13:10:58Z")

</div>

I have the same question @lassoan: is it possible to retain the color of the model in the segmentation?

I tried to use Probe volume with model, like you explain [here](https://discourse.slicer.org/t/creating-real-colour-models-using-visible-human-data/14627/2), but my results were very “weird”.

This is the volume rendering of the segmentation:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/a/2a33a52b64374fbc698897322c12ab6607eab8a2.jpeg)

This was the result with “Probe volume with model” \> “Direct color mapping”:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/8/0880bb2f25187896f8815f9e48f86b3b319216c3.png)

Change from “Direct color mapping” to “color table”:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/a/5a6071a0ccfba993ae32b4f9bcb4490efd001205.png)

---

<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:** [April 14, 2021, 3:01pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/17 "2021-04-14T15:01:55Z")

</div>

You would need to create a color map similar to the color transfer function that you use for volume rendering, but of course you will never get similar image quality with surface rendering as with volume rendering. This has been discussed previously in other topics, see for example here:

> [@Save volume rendering as STL file](https://discourse.slicer.org/t/save-volume-rendering-as-stl-file/524):
>
> Hello, I am a new user on 3D slicer. I was using the display preset feature under volume rendering, and I was wondering if there is a way to save what I was viewing as an .stl or 3D printable file. For example, I was viewing a sample MRI using the CT-cardiac3 preset display. When I tried to save that specific 3D preset displayed sample in a .stl file, the option was unavailable. I was only able to see .vp (volume property), .txt formats. Is there a way to accomplish what I desire in 3D slic…

---

<div class="post-metadata">

**Author:** ![tgterra](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tgterra](https://discourse.slicer.org/u/tgterra)\
**Post date:** [April 14, 2021, 8:09pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/18 "2021-04-14T20:09:13Z")

</div>

Thank you @lassoan for your reply. Could you help me to create this color map? I’m new with 3d slicer ☹

---

<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:** [April 15, 2021, 12:03am UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/19 "2021-04-15T00:03:42Z")

</div>

## For scalar (not RGB) volumes

You can copy the color transfer function to a color node by copy-pasting this into the Python console:

```python
volumeRenderingPropertyNode = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLVolumePropertyNode')
colorNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLProceduralColorNode')
colorNode.GetColorTransferFunction().DeepCopy(volumeRenderingPropertyNode.GetColor())

```

However, as I wrote above, do not expect surface rendering to even remotely similar to volume rendering, but something like this instead (left: volume rendering; right: surface rendering of probed surface):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/7/97f4020a47f1c415965d15702ea48ecd07efb497.jpeg)

The reason is that the texture/discoloration in the volume rendering is due to the cloud of lower or higher intensity voxels around the isosurface value, while in case of surface rendering the discoloration mainly comes from image interpolation artifacts (because if you segment by thresholding then you ideally get a surface where all the points have the exact same scalar value and any difference is due to small interpolation errors).

If you want a little bit more similar results then you can apply some Gaussian smoothing (using Gaussian Blur Image Filter module) to the input volume before you probe the volume with the model (that makes surrounding regions somewhat influence each point’s intensity):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6c4d343479df2b6a81558d0f1ad841f97cde379c.jpeg)

## For RGB volumes

If you have RGB volumes then you don’t need a colormap but you use direct color mapping. The fundamental difference between volume rendering/surface rendering still applies, and you’ll basically get a uniformly colored surface if you create segments by thresholding.

You must have chosen a wrong volume when you used Probe volume with model (not the RGB volume) if it came out like that in your screenshot. Try the probing again and if you cannot figure out what’s wrong then upload your scene as a .mrb file somewhere and post the link here.

I get this with the default red-green-blue colormap:

 ![2021-04-14_19-52-34](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/3/c31847f0466b62b303ed1b20eb3f8645c423933c.jpeg)

And this is what I see when I switch to direct mapping:

 ![2021-04-14_19-53-00](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/a/0a6acd0e377e5a986f2dd34f4129d41e93aec001.jpeg)

I’m not sure what your goal is, but I don’t think you can get realistic surface textures from the color in these cross-sectional images. If you want to see nice surface texture then it is better to take a photo of dissected organs and apply that texture to surface models.

---

<div class="post-metadata">

**Author:** ![tgterra](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tgterra](https://discourse.slicer.org/u/tgterra)\
**Post date:** [April 15, 2021, 1:07pm UTC](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294/20 "2021-04-15T13:07:06Z")

</div>

Wow, thank you so much @lassoan ! Your answer will help me a lot, thanks again!

[Next page](https://discourse.slicer.org/t/retain-image-color-in-volume-rendering/12294.md?page=2)
