【发布时间】:2013-03-28 13:00:32
【问题描述】:
我有一些数据,其中包含几个 2D 图像,我想使用 mayavi2 (v4.3.0) 在相对于彼此的特定 [x,y,z] 位置进行渲染。
From the documentation 看来我应该可以用mlab.imshow() 做到这一点。不幸的是,当我调用 imshow 并指定 extent 参数 (AttributeError: 'ImageActor' object has no attribute 'actor') 时,mayavi 会引发异常。
我还尝试通过修改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()
【问题讨论】:
标签: python image 3d transformation mayavi