2013-04-05 12 views
5

Ho alcuni dati che consistono in diverse immagini 2D che vorrei rappresentare in specifiche [x, y, z] posizioni l'una rispetto all'altra usando mayavi2 (v4.3.0).mayavi - impostazione programmata dell'estensione [x, y, z] di un'immagine

From the documentation sembra che dovrei essere in grado di farlo con mlab.imshow(). Sfortunatamente, mayavi lancia un'eccezione quando chiamo imshow specificando il parametro extent (AttributeError: 'ImageActor' object has no attribute 'actor').

Ho anche provato a impostare i dati x, ye direttamente modificando im.mlab_source.x,y,z.... Stranamente, sebbene questo modifichi correttamente le estensioni x e y, non fa nulla per la posizione z anche se im.mlab_source.z cambia chiaramente.

Ecco un esempio eseguibile:

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

risposta

5

Ok, si scopre che si tratta di una known bug in Mayavi. Tuttavia, è possibile modificare l'orientamento, la posizione e la scala di un oggetto ImageActor dopo la sua creazione:

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