Mayavi - 编程设置图像的[x,y,z]范围

6

我有一些由几个2D图像组成的数据,我想使用mayavi2(v4.3.0)在特定的[x,y,z]位置相对于彼此渲染。

从文档中看来,我应该可以使用mlab.imshow()来完成这个任务。不幸的是,当我调用imshow并指定extent参数时,mayavi会抛出异常(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()
1个回答

5

好的,事实证明这是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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接