Seems vtkImageReslice::SetResliceTransform doesn't change output spacing and extent

Hi, everyone.
I’m using vtk for working with 3D dicom images and faced with one problem.
If I use vtkImageReslice::SetResliceTransform functionality, the output spacing and extent of resulting dicom are not changed. It’s a little bit strange, because, in my opinion, if I rotate image around center on 90 degrees, extents and spacing of result should be changed.
For example, if I use vtkImageReslice::SetResliceAxes in same way then output extents and spacing are changed. But I need SetResliceTransform, not SetResliceAxes.
Do I miss something? Or maybe I need to use vtkImageChangeInformation with SetResliceTransform in order to get correct result?
Thanks!

You didn’t miss anything. The spacing, extent, etc. are only modified when you use SetResliceAxes(). With SetResliceTransform(), the sampling grid is unchanged.

There are two work-arounds:

  1. If your transform is a vtkTransform, call SetResliceAxes(transform->GetMatrix())
  2. Or, call SetOutputSpacing(), SetOutputExtent() to get the desired sampling

Don’t use vtkImageChangeInformation to try to “correct” the spacing after-the-fact.

Note that the transform passed to SetTransform() is not necessarily a linear transform. It can be anything, including transforms that stretch the image in some places and shrink or twist them in other places. So it isn’t necessarily possible to compute a uniform output spacing given the transform. So, instead, the input spacing is used by default, with the option of using SetSpacing() to choose a spacing.

1 Like

Hi, David. Thanks for the answer, very appreciate your help.

Actually my problem is a little bit tricky then I described

I use both SetResliceTransform and SetResliceAxes.
Because I want to rotate volume around the center at first (in order to get saggital view) and then apply SetResliceAxes (in this case I perfom rotation around random point)
And as result I got problem, that only SetResliceAxes affected spacing and extents. And I wondered how it can be worked together, if SetResliceTransform doesn’t affect spacing and extents,
then it means that SetResliceAxes works with wrong input spacing and extents.
I thought SetResliceTransform should change spacing and extents and then these values used as input for SetResliceAxes and then changed by SetResliceAxes and we get ouput result

Can SetResliceTransform and SetResliceAxes work together?

Things to try:

  1. Do it the other way around: Use SetResliceAxes() to change to sagittal, and use SetResliceTransform() to apply a random rotation. Then at least the sagittal image will have your desired spacing.

  2. Compose your two transformations into a single 4x4 matrix, and only use SetResliceAxes().

What first happens? SetResliceTransform or SetResliceAxes?

Second option seems to be good option. But when I investigated how works matrix in SetResliceAxes. It seems that third column of matrix considered as rotation center. I was confused, because in usual way if I want to rotate something around some point P I need matrix like this M = Translate(P) * Rotation * Translate(-P). But in case of SetResliceAxes vtk use Translate(P) * Rotation. This is strange for me. If 3d column is rotation center, how can I concatenate two reslice matrixes with different rotation centers?

Let’s define:
(x,y,z) are the output coordinates
(x’,y’,z’) as the input coordinates
T( ) is the ResliceTransform transformation function
A( ) is the ResliceAxes transformation function

The ImageReslice transformation function is:
(x’,y’,z’) = T( A( (x,y,z) ) )

The basic operation of vtkImageReslice is as follows: for each point (x,y,z) on the output sample grid, the corresponding (x’,y’,z’) point in the input coordinate system is computed by the equation given above. The input image is interpolated at (x’,y’,z’), and the interpolated value is used for the output sample at (x,y,z).

The units of the input and output are the same (if the input is DICOM, then the units are millimetres).

A is a 4x4 matrix, and usually T is also represented as a 4x4 matrix. The third column is not the center of rotation. Your math for rotation looks fine to me.

1 Like

So you mean, If I have two rotation points:
P1, P2 and two rotation matrices: R1, R2 . I can calculate two matrices:
M1 = Translation(P1) * R1 * Translation(-P1)
M2 = Translation(P2) * R2 * Translation(-P2)
concatenate them like M3 = M1 * M2. Then setup this matrix SetResliceAxes(M3).
And it should work?

If I have two rotation points:
P1, P2 and two rotation matrices: R1, R2 . I can calculate two matrices:
M1 = Translation(P1) * R1 * Translation(-P1)
M2 = Translation(P2) * R2 * Translation(-P2)
concatenate them like M3 = M1 * M2. Then setup this matrix SetResliceAxes(M3).

Yes. M1 occurs in the rotated coordinate system created by M2, and together, they produce M3.

It works, thanks!