Best way for rotating a matrix of data?

R

Raphaël Plasson

Hello,

after some computations, I obtain a 2D matrix of data, in a numpy
array. I can easily plot them using pyplot, and can easily extract
either vertical or horizontal slices by plotting a row or a column of
this matrix. I would like to be able to plot slices form this data
array, but with an arbitrary angle. Thus my question: what is the best
way to do so?

For the moment the solution I am using is to go through image
transformation, using PIL, by a function returning :
array(Image.fromarray(<data>).rotate(<angle>,resample=Image.BICUBIC))
In short, I convert the array in an image object, I rotate it, and
then convert it back to an array. Not very clean, rather a work around
than a solution, indeed.

Actually, I more precisely extract my 2D array from much higher
dimensions data (i.e. 10-20 fields of different data in 3 dimensions
of space+1 dimension of time), contained in a hdf5 file. I typically
would like to extract arbitrary slices of any of the fields from the
3+1D space... and I don't really know how this can be simply done. I
can only extract an "orthogonal" 2D space from this space, and rotate
it with the above method.

Is there a more direct way to extract arbitrary slices directly from
2/3/4D arrays? Which python modules would be able to do the job?

Thank you,

Raphael
 
N

Nobody

Actually, I more precisely extract my 2D array from much higher
dimensions data (i.e. 10-20 fields of different data in 3 dimensions
of space+1 dimension of time), contained in a hdf5 file. I typically
would like to extract arbitrary slices of any of the fields from the
3+1D space... and I don't really know how this can be simply done. I
can only extract an "orthogonal" 2D space from this space, and rotate
it with the above method.

Is there a more direct way to extract arbitrary slices directly from
2/3/4D arrays? Which python modules would be able to do the job?

You can use arrays as indices, so applying a transformation to a set of
index arrays (e.g. np.indices) then using those as indices is equivalent
to applying a spatial transform to the data.

Also: scipy.ndimage.
 
R

Raphaël Plasson

You can use arrays as indices, so applying a transformation to a set of
index arrays (e.g. np.indices) then using those as indices is equivalent
to applying a spatial transform to the data.

I am not sure that this would do the trick, e.g. for extracting a
transversal slice of a 3D array.
Also: scipy.ndimage.


But this seems to do exactly what I am looking for, thanks :). There
actually may be another solution, that is to use the VTK library.
However, it is a much more complex package, much more powerful but
maybe too much for what I want to do. The scipy.ndimage module ("Multi-
dimensional image processing") is probably the best solution for me.

Thank you,

Raphael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top