Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D Image Rotation Simple ITK Python

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.

like image 398
Noobie555 Avatar asked Jan 24 '26 14:01

Noobie555


1 Answers

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.

like image 180
blowekamp Avatar answered Jan 26 '26 08:01

blowekamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!