1

I used Mayavi to render a 3D volume as the following code:

from mayavi import mlab
vol_mlab = mlab.pipeline.volume(mlab.pipeline.scalar_field(M))
mlab.colorbar()
mlab.show()

where M is a 3D matrix. My question is that if the voxel has three values which describe the (R,G,B) components, is it possible to render a volume with color information ?

phan
  • 109
  • 8

1 Answers1

1

Several suggestions:

1) If your scalars and colors correspond to a common colormap, you should be able to set the colormap directly of the volume

2) You can customize the ColorTransferFunction of your volume as illustrated here: http://docs.enthought.com/mayavi/mayavi/auto/mlab_pipeline_other_functions.html#volume (reproduced below). So for your example, as long as your colors are smoothly varying with the scalar values, pick a few waypoints of your colors and add them into the CTF

vol = mlab.pipeline.volume(src)

# Changing the ctf:
from tvtk.util.ctf import ColorTransferFunction
ctf = ColorTransferFunction()
ctf.add_rgb_point(value, r, g, b)  # r, g, and b are float
                                   # between 0 and 1
ctf.add_hsv_point(value, h, s, v)
# ...
vol._volume_property.set_color(ctf)
vol._ctf = ctf
vol.update_ctf = True

3) Do you really need the volume rendering? If not, it may be easier visualize as 3D points and set a custom colormap, e.g. https://stackoverflow.com/a/30266228/209246. So this would look like assigning a scalar to each voxel, and then placing the voxel's RGB color into the corresponding row of a custom colormap.

Community
  • 1
  • 1
eqzx
  • 5,323
  • 4
  • 37
  • 54