I have derived a 4x4 transformation matrix t which I want to apply to a 3d vtkImageData.
To apply t to the imagedata I use vtkTransformFilter:
transform_filter = vtk.vtkTransformFilter()
If I create a contour of transform_filter it shows that the transformation is done correctly (since I know what the result should look like). However the light on the contour seems very weird, it is almost not visible.
I also tried applying t to the imagedata via vtkImageReslice:
resliced = vtk.vtkImageReslice()
However, when I create a contour of this result, the orientation of the object is different.
It seems applying transformation matrix t via vtkTransformFilter yields a different result from applying the same transformation matrix using vtkImageReslice. Therefore I was wondering if anybody would know what additional steps I would need to apply prior to transforming via vtkImageReslice to obtain the same result as with vtkTransformFilter.
Which VTK version do you use? VTK9 can represent rotated volumes, but the feature is very new and not all filters and mappers are updated to use image orientation.
vtkImageReslice can do what you need, but the filter has many operating modes, so you need to spend some time with understanding how to use it.
If you only need linear transformation then you may transform the actor instead of the image data.
Hi, I am using vtk 9.0.1 with Python3. I do need to apply the transformation to the imagedata (not the actor) since I need the transformed files, not just a visualization.
This is the original orientation of my object (the OBBs are in red):
After applying the vtkTransformFilter:
After applying vtkImageReslice:
For the result of the vtkTransformFilter the light is very dark, so the contour is not really visible, however its orientation is right. For the vtkImageReslice the lighting works, but the orientation is wrong.
However, for both methods I have used the same input (imagedata and transformation matrix)…
vtkImageReslice works well, it is just very versatile, so you need to know exactly what you are doing.
Note that images can be transformed using inverse (resampling) transform, while meshes can be transformed using modeling (forward) transform. So, you may need to invert a transform somewhere that you might not expect to be necessary.
Inversing t before applying it the ImageReslice made it work, thank you Andras!