Rotation/translation 具有插值的 vtk 3D 图像 (python)
Rotation/translation of vtk 3D image with interpolation (python)
我有 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 到 rotate/translate 之间创建一个函数并对其进行插值。
import vtk
def rotate(vtkinputpath, vtkoutputpath, rotation, translation, interpolation):
...
我正在尝试从 the transformJ plugin sources (see 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 文档,但这有助于理解 RotateWXYZ 的工作原理:http://www.vtk.org/doc/nightly/html/classvtkTransform.html#a9a6bcc6b824fb0a9ee3a9048aa6b262c
要创建您想要的变换,您可以将旋转和平移矩阵组合成一个 4x4 矩阵,为此我们将旋转矩阵放在列和行 0、1 和 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)
编辑:编辑完成矩阵变量中的值。
我有 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 到 rotate/translate 之间创建一个函数并对其进行插值。
import vtk
def rotate(vtkinputpath, vtkoutputpath, rotation, translation, interpolation):
...
我正在尝试从 the transformJ plugin sources (see 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 文档,但这有助于理解 RotateWXYZ 的工作原理:http://www.vtk.org/doc/nightly/html/classvtkTransform.html#a9a6bcc6b824fb0a9ee3a9048aa6b262c
要创建您想要的变换,您可以将旋转和平移矩阵组合成一个 4x4 矩阵,为此我们将旋转矩阵放在列和行 0、1 和 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)
编辑:编辑完成矩阵变量中的值。