Reputation: 33
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.
Upvotes: 3
Views: 4894
Reputation: 1431
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.
Upvotes: 4