3

I'm trying to rotate a 3D-Image with Simple ITK. Here is my Code: imagetoresize is the original image. The size of the image is (512,512,149)

targetimage = imagetoresize
origin = imagetoresize.GetOrigin()
targetimage = imagetoresize
imagetoresize.SetOrigin((0,0,0))
transform = sitk.VersorTransform((0,0,1), np.pi)
transform.SetCenter((256,256,74))
outimage=sitk.Resample(imagetoresize,targetimage.GetSize(),transform,sitk.sitkLinear,[0,0,0], imagetoresize.GetSpacing(), imagetoresize.GetDirection())
outimage.SetOrigin(origin)

The code rotates the image but the center is shifted.
Orginal Image Image after rotate

Can someone explain to me why the center is shifted?

Any help will be much appreciated.

Majid Parvin
  • 4,499
  • 5
  • 29
  • 47
Noobie555
  • 33
  • 1
  • 4
  • You appear to be assuming the physical points are the same as the indices of the image. Can you please share the rest of the meta-data of your image? The spacing, origin, and direction matrix. – blowekamp Jun 09 '17 at 15:14
  • Orginal: Dimension: 3 Dimensions: 512 512 149 Matrix: 0.832031 0 0 0 0.832031 0 0 0 1.5 Offset: [-200.584, -382.084, -1431.5] Center: [0, 0, 0] Translation: [-200.584, -382.084, -1431.5] Inverse: 1.20188 0 0 0 1.20188 0 0 0 0.666667 Scale : 1 1 1 Origin: [-200.584, -382.084, -1431.5] Spacing: [0.832031, 0.832031, 1.5] EvenlySpaced: 1 DirectionVector: [0, 0, 1] Slices: 149 – Noobie555 Jun 09 '17 at 16:35
  • Rotate: Dimension: 3 Dimensions: 512 512 149 Matrix: 0.832031 0 0 0 0.832031 0 0 0 1.5 Offset: [-200.584, -382.084, -1431.5] Center: [0, 0, 0] Translation: [-200.584, -382.084, -1431.5] Inverse: 1.20188 0 0 0 1.20188 0 0 0 0.666667 Scale : 1 1 1 Origin: [-200.584, -382.084, -1431.5] Spacing: [0.832031, 0.832031, 1.5] EvenlySpaced: 1 DirectionVector: [0, 0, 1] Slices: 149 – Noobie555 Jun 09 '17 at 16:36

1 Answers1

4

You are setting the center of rotation in pixels and not in physical space.

SimpleITK ( and ITK ) perform transformation and resampling in physical space and not index space. It should be unnecessary to set the origin of you image to 0. I believe the you should use imagetoresize.TransformContinuousIndexToPhysicalPoint(center_index) to obtain the center in physical space.

blowekamp
  • 1,401
  • 7
  • 7
  • Thanks your advice! it was really helpful. But i must set the origin to 0 otherwise i get a black image. – Noobie555 Jun 10 '17 at 11:27