简体   繁体   English

3D图像旋转简单ITK Python

[英]3D Image Rotation Simple ITK Python

I'm trying to rotate a 3D-Image with Simple ITK. 我正在尝试使用简单ITK旋转3D图像。 Here is my Code: imagetoresize is the original image. 这是我的代码: imagetoresize是原始图像。 The size of the image is (512,512,149) 图像的大小为(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. 任何帮助都感激不尽。

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. SimpleITK(和ITK)在物理空间而不是索引空间中执行转换和重新采样。 It should be unnecessary to set the origin of you image to 0 . 不必将图像的原点设置为0 I believe the you should use imagetoresize.TransformContinuousIndexToPhysicalPoint(center_index) to obtain the center in physical space. 我相信您应该使用imagetoresize.TransformContinuousIndexToPhysicalPoint(center_index)获得物理空间中的中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM