我有一些由几个2D图像组成的数据,我想使用mayavi2 (v4.3.0)
在特定的[x,y,z]位置相互渲染。
从文档看来,我应该能够做到这一点与mlab.imshow()
。不幸的是,mayavi抛出一个异常,当我调用imshow
指定extent
参数(AttributeError: 'ImageActor' object has no attribute 'actor'
)。
我还尝试通过修改im.mlab_source.x,y,z...
直接设置x,y和z数据。奇怪的是,虽然这正确地改变了x和y范围,但它对z位置没有任何影响,即使im.mlab_source.z
明显改变了。
下面是一个可运行的例子:
import numpy as np
from scipy.misc import lena
from mayavi import mlab
def normal_imshow(img=lena()):
return mlab.imshow(img,colormap='gray')
def set_extent(img=lena()):
return mlab.imshow(img,extent=[0,100,0,100,50,50],colormap='cool')
def set_xyz(img=lena()):
im = mlab.imshow(img,colormap='hot')
src = im.mlab_source
print 'Old z :',src.z
src.x = 100*(src.x - src.x.min())/(src.x.max() - src.x.min())
src.y = 100*(src.y - src.y.min())/(src.x.max() - src.y.min())
src.z[:] = 50
print 'New z :',src.z
return im
if __name__ == '__main__':
# this works
normal_imshow()
# # this fails (AttributeError)
# set_extent()
# weirdly, this seems to work for the x and y axes, but does not change
# the z-postion even though data.z does change
set_xyz()
好的,原来这是mayavi中一个已知的bug。但是,可以在创建ImageActor
对象后更改其方向、位置和比例:
obj = mlab.imshow(img)
obj.actor.orientation = [0, 0, 0] # the required orientation
obj.actor.position = [0, 0, 0] # the required position
obj.actor.scale = [0, 0, 0] # the required scale