# Export colorized volume to .gltf

**URL:** <https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [August 16, 2024, 12:02pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915 "2024-08-16T12:02:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [August 16, 2024, 12:02pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/1 "2024-08-16T12:02:37Z")

</div>

Dear community:  
I am starting to use the colorize volume extension, got my colorized volume, but can´t export it to .gltf through the OpenAnatomy export extension. My objective is to show the colorized volume online.  
Any hints would be welcomed.  
Best regards,

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 16, 2024, 2:46pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/2 "2024-08-16T14:46:57Z")

</div>

No, you won’t be able to do that since Colorized Volumes are RGBA image data but gltf only support polygonal surface data.

---

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [August 17, 2024, 1:05pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/3 "2024-08-17T13:05:00Z")

</div>

Thanks, Steve. This means that this module is only standalone for Slicer? I mean, its rendering is not displayable by the Online3DViewer, for instance?  
Best,  
Rafael

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [August 17, 2024, 1:39pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/4 "2024-08-17T13:39:00Z")

</div>

3dviewer can only display surface.models. try the Glance viewer from Kitware if you want to see the colorized voxels. I believe it supports rgb images

> **[Kitware Glance](https://kitware.github.io/glance/app/)**
>
> Data Viewer in a browser

---

<div class="post-metadata">

**Author:** ![Thibault\_Bruyere](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thibault_bruyere/32/67736_2.png) [@Thibault\_Bruyere](https://discourse.slicer.org/u/Thibault_Bruyere)\
**Post date:** [August 19, 2024, 8:05am UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/5 "2024-08-19T08:05:11Z")

</div>

Hello,  
An alternative to Kitware Glance is Kitware Volview, that is specialized in rendering of medical volumes. It is also a little bit more maintained.  
They are both based on vtk.js, and there are a lot of useful new features that are not used yet in Glance/Volview, so you could try using an example to make your own viewer.  
[https://volview.kitware.app/](https://volview.kitware.app/)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 19, 2024, 1:51pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/6 "2024-08-19T13:51:01Z")

</div>

@Rafael_V_Monteiro let us know what you find if you try VolView and/or Glance. In addition to vtk.js in native javascript, there is also a path to use traditional C[++ VTK with WebAssembly](https://docs.vtk.org/en/latest/getting_started/using_webassembly.html) to render in browsers. Both of these rely on WebGL which can in theory render the RGBA volumes generated by the ColorizeVolume module, but I don’t know if those code paths have been debugged on the WebGL side of things in either C++ VTK or vtk.js. It [took a while](https://github.com/Slicer/VTK/pull/43) to get it fixed in the OpenGL version.

---

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [August 19, 2024, 2:37pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/7 "2024-08-19T14:37:55Z")

</div>

Absolutely Steve. I´ll look into it and report back.  
Thank you!  
Rafael

---

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [September 17, 2024, 9:53am UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/8 "2024-09-17T09:53:18Z")

</div>

Dear @pieper , @muratmaga , @Thibault_Bruyere:  
I tried to play with the colorized model and displayed the model with the suggested viewers, Glance and Volview.  
My colorized model was as below:

 ![coati colorized slicer](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/f/afaefb1447b95515a869701c06140f8041c6c306.jpeg)

The only way I found out to export it to rgb capable formats was through the data module, right click on the colorized volume and export to file. The formats I found reasonable were the .nrrd and .vtk. I tried to view both formats on the viewers above quoted. VolView was able to open both .vtk and .nrrd files, results below:

 ![coati nrrd volview](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/9/d9843105eb4a6bf9eebcce9b1d66330386276113.png)  
nrrd

 ![coati vtk volview](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/9/c95c3dc6ab2588928bdd047935526e7d0ddc14a5.png)

vtk

Glance was able to open only .nrrd format:

 ![coati nrrd glance](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/c/ccc7dcd5757f53eb4bf3ba7a688a65f4fae78e35.jpeg)

Its clear that none of them was able to reproduce the details shown in slicer.  
Any suggestions were to go from here? Very thanks in advance,  
Rafael

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 17, 2024, 10:30am UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/9 "2024-09-17T10:30:20Z")

</div>

You cannot save a volume rendering, colorized or not. It is just a visual representation of volumetric data. I suggest reading this thread where this was discussed in detail:

> [@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:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 17, 2024, 1:25pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/10 "2024-09-17T13:25:43Z")

</div>

Thanks for testing this @Rafael_V_Monteiro. As noted above, in order to implement this feature we needed to fix the shader in VTK C++ to support using the alpha channel as opacity and configure the rendering pipeline to use that mode. I’m not sure any of the web based rendering systems support that configuration. There’s nothing in theory that prevents it from working, but it may require debugging and also proper configuration to replicate the view you see in Slicer. Making this work probably requires learning the source code and tracing the rendering path for RGBA mode (need to work in javascript, webgl, glsl, …).

---

<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 17, 2024, 2:02pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/11 "2024-09-17T14:02:51Z")

</div>

@Rafael_V_Monteiro in all your tests, the volume rendering was done with “independent components” flag enabled. Independent component means that the scalar components of the volume are rendered independently (not as a colored voxel). You need to set `volumeProperty.SetIndependentComponents(false)` if you want color rendering. For more realistic rendering you also need to carefully set up transfer functions, lighting, volumetric screen-space ambient occlusion, etc.

If you use a recent C++ VTK version then you don’t need any code change. Not all these features are available in vtk.js (and if they are then similar fixes may be needed as in C++ VTK), so I would recommend to use WebAssembly VTK in your web browser.

---

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [September 17, 2024, 2:22pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/12 "2024-09-17T14:22:13Z")

</div>

I will look into, thanks @cpinter !

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 17, 2024, 2:24pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/13 "2024-09-17T14:24:07Z")

</div>

Based on the reactions I may have misunderstood something and just reacted without seeing the whole picture. But it may be useful regardless…

---

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [September 17, 2024, 2:24pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/14 "2024-09-17T14:24:08Z")

</div>

Dear @pieper, this seems beyond my programming capabilities…But I will study it anyway to see if I get someplace.  
Best regards,

---

<div class="post-metadata">

**Author:** ![Rafael\_V\_Monteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafael_v_monteiro/32/16558_2.png) [@Rafael\_V\_Monteiro](https://discourse.slicer.org/u/Rafael_V_Monteiro)\
**Post date:** [September 17, 2024, 2:27pm UTC](https://discourse.slicer.org/t/export-colorized-volume-to-gltf/37915/15 "2024-09-17T14:27:22Z")

</div>

Thank you @lassoan , I will do the modification in the volume rendering to see what happens. I also will give a try to vtk.js, maybe it is the way.  
Best regards,
