colorize_volume.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. """Custom color and transparency maps for Volumes"""
  2. from vedo import Volume, dataurl, show
  3. from vedo.pyplot import CornerHistogram
  4. # Build a Volume object.
  5. # A set of color/transparency values - of any length - can be passed
  6. # to define the transfer function in the range of the scalar.
  7. # E.g.: setting alpha=[0, 0, 0, 1, 0, 0, 0] would make visible
  8. # only voxels with value close to center of the range (see histogram).
  9. vol = Volume(dataurl + "embryo.slc")
  10. vol.color(
  11. [
  12. (0, "green"),
  13. (49, "green"),
  14. (50, "blue"),
  15. (109, "blue"),
  16. (110, "red"),
  17. (180, "red"),
  18. ]
  19. )
  20. # vol.mode('max-projection')
  21. vol.alpha([0.0, 1.0])
  22. vol.alpha_unit(8) # absorption unit, higher factors = higher transparency
  23. vol.add_scalarbar3d(title="color:dot:alpha transfer function", c="k")
  24. # substitute scalarbar3d to a 2d scalarbar
  25. vol.scalarbar = vol.scalarbar.clone2d("center-right", 0.2)
  26. ch = CornerHistogram(vol, logscale=True, pos="bottom-left")
  27. # show both Volume and Mesh
  28. show(vol, ch, __doc__, axes=1, zoom=1.2).close()