Transforming imagedata via vtkTransformFilter vs. vtkImageReslice

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()
transform_filter.SetInputData(imgdata)
transform_filter.SetTransform(t)
transform_filter.Update()

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()
resliced.SetInputData(imgdata)
resliced.SetAutoCropOutput(True)
resliced.SetResliceTransform(t)
resliced.SetInterpolationModeToLinear()
resliced.Update()

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.

1 Like

Inversing t before applying it the ImageReslice made it work, thank you Andras!

1 Like

How to Transform DICOM Images Without Using vtkImageReslice? I want to rotate image data from DICOM files, but I don’t want to use vtkImageReslice because it changes the positions of the tuples

Depending on what VTK version you are using and what features are needed, it may be enough to change the image direction in the vtkImageData or you have to use vtkImageReslice/vtkImagePermute.

Thank you for your reply.

I am using VTK 9.2 with .NET 6. I have an IsoCenter point that marks a specific position on my DICOM images. When the imageData is rotated, the IsoCenter point should remain in the same position on the image as it was before the rotation.

For example, if the DICOM image represents a body and the IsoCenter point is at the center of the left eye, when the body is rotated 90 degrees around any axis (x, y, or z), the IsoCenter point should still be at the center of the left eye.

That should be no problem at all. You can put together a transform that rotates around a specific point by shifting to the point, rotating, and shifting back. The transform can be used for either updating the IndexToPhysical transform in the vtkImageData or used in vtkImageResample.

If you want to verify that you compute and concatenate transforms correctly, you can use the latest preview release of 3D Slicer, which provides a convenient GUI to rotate images around an arbitrary point and inspect the transformation matrix.

Hello, using VTK 9.3.1 I can transform a vtkImage (using a landmark transformation), but the output is a vtkStructuredGrid.

I understand that this was expected since in the past vtkImage did not support rotation, but now it should support it, so is there a way to output a vtkImage?

(this will make things easier in other parts of my code)

Usually a warping transform is applied to an image by using vtkImageResample filter.