Is it possible to directly apply an affine transformation matrix to a Mayavi ImageActor object? Is it possible to directly apply an affine transformation matrix to a Mayavi ImageActor object? python python

Is it possible to directly apply an affine transformation matrix to a Mayavi ImageActor object?


ImageActor, which ultimately is a wrapper for tvtk.ImageActor, has a user_matrix property, which lets you assign a 4D transformation matrix.

Starting with a random image,

    import numpy as np    from mayavi.mlab import imshow    s = np.random.random((10, 10))    image = imshow(s, colormap='gist_earth', interpolate=False)

gives us the following ...

Random image

Creating a transformation matrix and setting a term to give it some shear ...

    from tvtk.api import tvtk    transform_matrix = tvtk.Matrix4x4()    transform_matrix.set_element(0, 1, 2.5)    image.actor.user_matrix = transform_matrix

gives us ...

Random image with shear

set_element has the signature (row, col, value), so you should be able to set elements on that matrix as needed.