从SimpleITK转换获取矩阵和转换

时间:2018-09-18 16:34:13

标签: python simpleitk

我正在从文件中读取ITK转换。我无法弄清楚直接从转换中获取 Translation Matrix 的API。

t = sitk.ReadTransform('sample_transform.h5')
print(t)

这是打印的结果:

itk::simple::Transform
VersorRigid3DTransform (0x55c3e22f5de0)
RTTI typeinfo:   itk::VersorRigid3DTransform<double>
Reference Count: 1
Modified Time: 802
Debug: Off
Object Name: 
Observers: 
 none
Matrix: 
 0.999862 0.016289 0.00333268 
 -0.0161218 0.998848 -0.0451944 
 -0.00406501 0.0451344 0.998973 
Offset: [-1.3857, 0.238944, 0.984074]
Center: [36.1356, 6.81771, -27.0756]
Translation: [-1.36988, 0.872183, 1.17271]
Inverse: 
 0.999862 -0.0161218 -0.00406501 
 0.016289 0.998848 0.0451344 
 0.00333268 -0.0451944 0.998973 
Singular: 0
Versor: [ 0.0225887, 0.00184996, -0.00810505, 0.99971 ]

有没有直接获得Matrix和Translation的函数?

看起来可以从t.GetParameters()的最后三项中检索翻译:

print(t.GetParameters())

将给出:

(0.02258874140769294,
 0.0018499585651891462,
 -0.00810504740162434,
 -1.3698806341361933,
 0.8721829896773953,
 1.1727120470384382) 

1 个答案:

答案 0 :(得分:2)

ReadTransform方法始终返回std :: Transform基类。该通用接口可能很有用。有时您需要派生的接口,该接口提供诸如GetTranslationGetMatrix [1]之类的有用方法。只需通过转换/发布基本转换即可完成:

myVersorTransform = VersorRigid3DTransform(t)

[1] https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1VersorRigid3DTransform.html