一、vtk安装
命令:pip install vtk
二、vtk相关操作
1、读取dicom文件
v16 = vtk.vtkDICOMImageReader()
v16.SetDataByteOrderToLittleEndian()
v16.SetDirectoryName(dicom_path)
v16.SetDataSpacing(Space[0], Space[1], Space[2])
v16.Update()
2、截取ROI,源数据类型最好是volume
extractVOI = vtk.vtkExtractVOI()
extractVOI.SetInputConnection(v16.GetOutputPort())
print(extractVOI.GetVOI())
extractVOI.SetVOI(A) # set bounds int[6]
extractVOI.Update()
3、读mha文件
reader = vtk.vtkMetaImageReader()
reader.SetFileName('0.mha')
reader.SetDataSpacing(Space[0], Space[1], Space[2])
reader.Update()
4、模型平移(貌似没什么用)
trans = vtk.vtkTransform()
trans.Translate(1000, 0, 0) # 平移x y z
transformFilter = vtk.vtkTransformPolyDataFilter()