Mayavi中 - 设置图像的[X,Y,Z]范围内编程 [英] mayavi - setting the [x,y,z] extent of an image programatically

查看:620
本文介绍了Mayavi中 - 设置图像的[X,Y,Z]范围内编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据,它由几个2D图像,我想具体[X,Y,Z]渲染的位置相对于利用彼此 mayavi2(V4.3.0)

从文档似乎我应该能够与 mlab.imshow做到这一点()。不幸的是,Mayavi中抛出当我打电话异常 imshow 指定范围参数( AttributeError异常: ImageActor'对象有没有属性'演员')。

我还试图通过修改 im.mlab_source.x,Y,Z ... 直接设置x,y和z数据。古怪,而这正确地改变x和y的范围,它什么都不做的z位置,即使 im.mlab_source.z 明确改变。

下面是一个可运行的例子:

 进口numpy的为NP
从scipy.misc进口莉娜
从Mayavi的进口MLAB

高清normal_imshow(IMG =莉娜()):
    返回mlab.imshow(IMG,颜色表=灰色)

高清set_extent(IMG =莉娜()):
    返回mlab.imshow(IMG,程度= [0,100,0,100,50,50],颜色表=酷)

高清set_xyz(IMG =莉娜()):
    IM = mlab.imshow(IMG,颜色表=热)
    SRC = im.mlab_source
    打印老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
    打印新的z:,src.z
    回报IM

如果__name__ =='__main__':

    #这个工程
    normal_imshow()

    ##失败(AttributeError异常)
    #set_extent()

    #古怪,这似乎工作的x和y轴,但不改变
    #在Z-现在的位置,即使data.z不改变
    set_xyz()
 

解决方案

好吧,事实证明,这是一个的在Mayavi中已知的bug 。然而,这是可以改变的 ImageActor 对象的方向,位置和比例,已经创建后:

  OBJ = mlab.imshow(IMG)
obj.actor.orientation = [0,0,0]#所需方向
obj.actor.position = [0,0,0]#所需位置
obj.actor.scale = [0,0,0]#所需规模
 

I have some data that consists of several 2D images that I would like to render in specific [x,y,z] positions relative to one another using mayavi2 (v4.3.0).

From the documentation it seems that I should just be able to do this with mlab.imshow(). Unfortunately, mayavi throws an exception when I call imshow specifying the extent parameter (AttributeError: 'ImageActor' object has no attribute 'actor').

I also tried setting the x,y and z data directly by modifying im.mlab_source.x,y,z.... Weirdly, whilst this correctly changes the x and y extents, it does nothing to the z-position even though im.mlab_source.z clearly changes.

Here's a runnable example:

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()

解决方案

Ok, it turns out that this is a known bug in mayavi. However, it is possible to change the orientation, position and scale of an ImageActor object after it has been created:

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

这篇关于Mayavi中 - 设置图像的[X,Y,Z]范围内编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆