转换itk(nifti图像)到vtk

时间:2019-12-16 14:12:51

标签: python vtk itk

我想将nifti文件转换为.vtk,我使用了此python代码

import itk
import vtk

读取输入文件

input_filename = ‘/home/nour/Bureau/244seg_pve_2.nii.gz’
PixelType = itk.ctype(‘float’)
Dimension = 3
ImageType = itk.Image[PixelType, Dimension]
reader = itk.ImageFileReader[ImageType].New()
reader.SetFileName(input_filename)
reader.Update()

细分

thresholdFilter = itk.ThresholdImageFilter[ImageType].New()
thresholdFilter.SetInput(reader.GetOutput())
thresholdFilter.ThresholdBelow(0)
thresholdFilter.SetOutsideValue(0)
thresholdFilter.Update()

itktovitk

itkToVtkFilter = itk.ImageToVTKImageFilter[ImageType].New()
itkToVtkFilter.SetInput(thresholdFilter.GetOutput())
myvtkImageData = itkToVtkFilter.GetOutput()
itkToVtkFilter.Update()

生成等值面

contour=vtk.vtkMarchingCubes()
contour.SetInputData(itkToVtkFilter.GetOutput())
contour.ComputeNormalsOn()
#contour.Update()

当我使用itkToVtkFilter.Update()运行它时:分割错误(核心已转储) 但是当我在没有itkToVtkFilter.Update()的情况下运行它时:vtkMarchingCubes(0x4d03f80):必须定义轮廓标量

0 个答案:

没有答案