【问题标题】:mayavi - setting the [x,y,z] extent of an image programaticallymayavi - 以编程方式设置图像的 [x,y,z] 范围
【发布时间】: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


    【解决方案1】:

    好的,原来这是 mayavi 中的known 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2010-10-07
      • 2017-02-26
      相关资源
      最近更新 更多