【问题标题】:Rotation/translation of vtk 3D image with interpolation (python)带插值的 vtk 3D 图像的旋转/平移(python)
【发布时间】:2016-05-26 16:37:56
【问题描述】:

我有 2 个矩阵:

#for example
rotation = matrix([[ 0.61782155,  0.78631834,  0.        ],
            [ 0.78631834, -0.61782155,  0.        ],
            [ 0.        ,  0.        , -1.        ]])
translation = matrix([[-0.33657291],
            [ 1.04497454],
            [ 0.        ]])
vtkinputpath = "/hello/world/vtkfile.vtk"
vtkoutputpath = "/hello/world/vtkrotatedfile.vtk"
interpolation = "linear"

我有一个包含 3D 图像的 vtk 文件,我想在 python 中创建一个函数来旋转/平移并对其进行插值。

import vtk

def rotate(vtkinputpath, vtkoutputpath, rotation, translation, interpolation):
  ...

我正在尝试从the transformJ plugin sources(见here to understand how it works)获得灵感

我想使用 vtk.vtkTransform 但我真的不明白它是如何工作的:这些examples 离我想要做的还不够近。这就是我所做的:

reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(vtkinputpath)
reader.Update()
transform = reader.vtkTransform()
transform.RotateX(rotation[0])
transform.RotateY(rotation[1])
transform.RotateZ(rotation[2])
transform.Translate(translation[0], translation[1], translation[2])
#and I don't know how I can choose the parameter of the interpolation

但这行不通... 我看到here RotateWXYZ() 函数存在:

# create a transform that rotates the cone
transform = vtk.vtkTransform()
transform.RotateWXYZ(45,0,1,0)
transformFilter=vtk.vtkTransformPolyDataFilter()
transformFilter.SetTransform(transform)
transformFilter.SetInputConnection(source.GetOutputPort())
transformFilter.Update()

但我不明白这些线条的作用。 我的主要问题是我找不到 Python 的 vtk 文档...

你能给我推荐一个 Python 中 vtk 的文档网站吗?或者你能至少解释一下 vtktransform (rotateWXYZ()) 是如何工作的吗? 拜托,我完全迷路了,没有任何作用。

【问题讨论】:

    标签: python image-processing interpolation vtk image-rotation


    【解决方案1】:

    我不确定是否有特定的 Python 文档,但这有助于了解 RotateWXYZ 的工作原理:http://www.vtk.org/doc/nightly/html/classvtkTransform.html#a9a6bcc6b824fb0a9ee3a9048aa6b262c

    要创建您想要的变换,您可以将旋转和平移矩阵组合成一个 4x4 矩阵,为此我们将旋转矩阵放在第 0、1 和 2 列和第 2 行中,我们将平移向量放在右列中,即底行是 0,0,0,1。 Here's some more info about this。例如:

    0.61782155   0.78631834  0      -0.33657291
    0.78631834  -0.61782155  0       1.04497454
    0            0          -1       0
    0            0           0       1
    

    然后可以直接使用SetMatrix设置矩阵为vtkTransform:

    matrix = [0.61782155,0.78631834,0,-0.33657291,0.78631834,-0.61782155,0,1.04497454,0,0,-1,0,0,0,0,1]
    transform.SetMatrix(matrix)
    

    编辑:编辑完成矩阵变量中的值。

    【讨论】:

    • 我阅读了您的链接描述,谢谢。但我不确定我是否理解 SetMatrix 函数......我正在尝试将我的旋转矩阵转换为角度和向量( 旋转轴)。我试图了解 vtkTransform (vtk.org/doc/nightly/html/vtkTransform_8h_source.html) 的来源,但我不确定我是否理解它的作用......非常感谢,如果我的尝试也不起作用,我会更新我的问题。跨度>
    • 我编辑了答案以在矩阵中显示正确的值。如果使用SetMatrix 将该矩阵设置为变换,则会得到一个应用示例中给出的旋转和平移的变换。之后,您可以使用 vtkImageReslice 将变换应用于图像。我希望这对您有所帮助。
    猜你喜欢
    • 2011-10-24
    • 2017-02-15
    • 2014-06-30
    • 2011-05-18
    • 1970-01-01
    • 2013-04-11
    • 2016-07-09
    • 1970-01-01
    相关资源
    最近更新 更多