[Paraview] rotating and shifting image data

Martin Luessi m-luessi at northwestern.edu
Wed Nov 25 13:57:16 EST 2009


Hi,

I'm working on a python script to open MRI images in NIFTI format in
paraview. I'm using "simple.ImageReader" to read the volume data.
However, the file header specifies a 4x4 matrix which transforms voxel
indices to coordinates in a reference coordinate system in mm, and I
would like to use the mm coordinates in paraview.

There is a VTK thread on doing this
(http://old.nabble.com/world-coordinates-and-image-data-td22217332.html)
and the solution was to use "vtkImageReslice" together with a
transform using "vtkMatrix4x4". However, the "vtkImageReslice" filter
does not seem to be present in the VTK version that comes with
ParaView (3.6.1-r1 on Gentoo). (Apart from this I couldn't figure out
how to use VTK filters on "simple.ImageReader").

Since this didn't work, I tried a different method. The 4x4 matrix in
the file is usually purely rotational and translational, I can extract
the rotation and translation parameters for each dimension from the
matrix and then simply rotate and shift the Image object. This can be
done in Python using

...
simple.Show(img)
props = simple.GetDisplayProperties(img)
props.Orientation = (180*alpha/pi, 180*beta/pi, 180*gamma/pi)
props.Position     = (tx, ty, tz)
...

Where img is the "simple.ImageReader" object. This does rotate and
translate the volume (image). However, the problem is that if apply a
filter on it (e.g. Slice) the output of the filter is not shifted and
translated, and thus does not appear at the same location as the
image. I also tried using "simple.Transform" for the rotation and
translation, but it looks like it doesn't support Image objects as
input.

Any hints on how to do this are greatly appreciated.

Martin


More information about the ParaView mailing list