# How to render a volume by vector?

**URL:** <https://discourse.slicer.org/t/how-to-render-a-volume-by-vector/17526>\
**Category:** Support\
**Tags:** visualization\
**Created:** [May 8, 2021, 2:30pm UTC](https://discourse.slicer.org/t/how-to-render-a-volume-by-vector/17526 "2021-05-08T14:30:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 10, 2021, 4:44am UTC](https://discourse.slicer.org/t/how-to-render-a-volume-by-vector/17526/2 "2021-05-10T04:44:45Z")

</div>

If k1 and k2 are intensity and gradient then you can use VTK’s 2D transfer function (an image that assigns RGBA value for coordinate pairs). See description of the transfer function [here](https://blog.kitware.com/2d-transfer-function-support-in-gpuvolumemapper/#:~:text=A%202D%20transfer%20function%20is%20defined%20as%20a,backend%29.%20More%20information%20can%20be%20found%20in%20TestGPURayCastTransfer2D). You can set the 2D transfer function by typing this into the Python console:

```python
slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLVolumePropertyNode").GetVolumeProperty().SetTransferFunction2D(image)

```

If k1 and k2 are arbitrary scalar components then you can apply your 2D transfer function to the volume to get an RGBA volume (e.g., using numpy) and use that as input for volume rendering.  
To render an RGBA volume, you need to [turn off independent component volume property option](https://discourse.slicer.org/t/merge-colored-images-and-show-them-as-1-volume/6472/6)).

---

_[View the full topic](https://discourse.slicer.org/t/how-to-render-a-volume-by-vector/17526)._
