python - mayavi - setting the [x,y,z] extent of an image programatically -
i have data consists of several 2d images render in specific [x,y,z] positions relative 1 using mayavi2 (v4.3.0)
.
from documentation seems should able mlab.imshow()
. unfortunately, mayavi throws exception when call imshow
specifying extent
parameter (attributeerror: 'imageactor' object has no attribute 'actor'
).
i tried setting x,y , z data directly modifying im.mlab_source.x,y,z...
. weirdly, whilst correctly changes x , y extents, nothing z-position though im.mlab_source.z
changes.
here's runnable example:
import numpy np scipy.misc import lena 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__': # works normal_imshow() # # fails (attributeerror) # set_extent() # weirdly, seems work x , y axes, not change # z-postion though data.z change set_xyz()
ok, turns out known bug in mayavi. however, possible change orientation, position , scale of imageactor
object after has been created:
obj = mlab.imshow(img) obj.actor.orientation = [0, 0, 0] # required orientation obj.actor.position = [0, 0, 0] # required position obj.actor.scale = [0, 0, 0] # required scale
Comments
Post a Comment