在Mayavi体积可视化中使用感知均匀的颜色图

在Mayavi体积可视化中使用感知均匀的颜色图

本文介绍了在Mayavi体积可视化中使用感知均匀的颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AFAIK Mayavi没有附带任何在感知上统一的颜色图。我天真地尝试将其传递给,但失败了:

AFAIK Mayavi does not come with any perceptually uniform colormaps. I tried naively to just pass it one of Matplotlib's colormaps but it failed:

from mayavi import mlab
import multiprocessing
import matplotlib.pyplot as plt

plasma = plt.get_cmap('plasma')

...
mlab.pipeline.volume(..., colormap=plasma)








编辑:我发现,用于将Matplotlib颜色图转换为Mayavi颜色图。但是,不幸的是,它不起作用,因为我正尝试使用通过感知均匀的颜色图使用的体积。


I found a guide to convert Matplotlib colormaps to Mayavi colormaps. However, it unfortunately doesn't work since I am trying to use a volume using a perceptually uniform colormap.

from matplotlib.cm import get_cmap
import numpy as np
from mayavi import mlab

values = np.linspace(0., 1., 256)
lut_dict = {}
lut_dict['plasma'] = get_cmap('plasma')(values.copy())

x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

mlab.pipeline.volume(mlab.pipeline.scalar_field(s), vmin=0, vmax=0.8, colormap=lut_dict['plasma'])  # still getting the same error
mlab.axes()
mlab.show()

...

推荐答案

如果将其设置为该卷的 ColorTransferFunction ,而不是将其设置为 colormap 参数,

Instead of setting it as the colormap argument, if you set it as the ColorTransferFunction of the volume, it works as expected.

import numpy as np
from mayavi import mlab
from tvtk.util import ctf
from matplotlib.pyplot import cm

values = np.linspace(0., 1., 256)
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

volume = mlab.pipeline.volume(mlab.pipeline.scalar_field(s), vmin=0, vmax=0.8)
# save the existing colormap
c = ctf.save_ctfs(volume._volume_property)
# change it with the colors of the new colormap
# in this case 'plasma'
c['rgb']=cm.get_cmap('plasma')(values.copy())
# load the color transfer function to the volume
ctf.load_ctfs(c, volume._volume_property)
# signal for update
volume.update_ctf = True

mlab.show()

这篇关于在Mayavi体积可视化中使用感知均匀的颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:57