2012-06-04 254 views
1

我想通過itk讀取nrrd文件並通過vtk顯示它。 但我有一些麻煩將itk轉換爲vtk。如何使用python將itk映像文件轉換爲vtk?

import itk 


file_name = '/home/yao/workspace/test/1.nrrd' 
image_type = itk.Image[itk.UC, 2] 
reader = itk.ImageFileReader[image_type].New() 
reader.SetFileName(file_name) 
reader.Update() 

itk_vtk_converter = itk.ImageToVTKImageFilter[image_type].New() 
itk_vtk_converter.SetInput(reader.GetOutput()) 
itk_vtk_converter.Update() 

和我得到的消息

Traceback (most recent call last): File "ex1.py", line 11, in <module> 
    itk_vtk_converter = itk.ImageToVTKImageFilter[image_type].New() File "/usr/lib/InsightToolkit/WrapITK/Python/itkLazy.py", line 14, in 
__getattribute__ 
    value = types.ModuleType.__getattribute__(self, attr) AttributeError: 'LazyITKModule' object has no attribute 'ImageToVTKImageFilter' 

我使用itk3.20,python2.7。 我該如何解決它?

問候。

回答

0

您的代碼是正確的。我想你可能無法在Python中正確構建itk。在我看來,在Python中使用ITK/VTK最簡單的方法是使用Pythonxy。你可以嘗試一下。

0

使用最新版本的ITK 4,它具有這些類的包裝(您必須在CMake配置中啓用ITKVtkGlue模塊)。

0

我不知道爲什麼它不工作,因爲我沒有直接從ITK嘗試VTk,但你可以嘗試使用這段代碼。

def itkImageToVtk(image): 
    arrayData = sitk.GetArrayFromImage(image) 
    print arrayData.flags 
    arrayDataC = np.array(arrayData[:,:,1], order='C') 
    print arrayDataC.flags 
    ArrayDicom = numpy_support.numpy_to_vtk(arrayDataC) 

它的2D ITK圖像轉換成2D VTK

相關問題