简体   繁体   English

如何在 VTK 管道(Python)中使用 VTK_array?

[英]How to use VTK_array in VTK pipeline (Python)?

I am new to vtk and am trying to do volume rendering with a DICOM file.我是vtk新手,正在尝试使用 DICOM 文件进行体积渲染。

When I try to read the DICOM file using VTK with the following code:当我尝试使用 VTK 和以下代码读取 DICOM 文件时:

import vtk
reader = vtk.vtkDICOMImageReader()
reader.SetDirectoryName(r"C:\Users\I_0001")
reader.Update()

I get the following error:我收到以下错误:

ERROR: In ..\IO\Image\vtkDICOMImageReader.cxx, line 143
vtkDICOMImageReader (000001DC61D2FED0): Couldn't open C:\Users\I_0001

ERROR: In ..\IO\Image\vtkDICOMImageReader.cxx, line 237
vtkDICOMImageReader (000001DC61D2FED0): Either a filename was not specified or the specified directory does not contain any DICOM images.

ERROR: In ..\Common\ExecutionModel\vtkExecutive.cxx, line 753
vtkCompositeDataPipeline (000001DC5C4A0A90): Algorithm vtkDICOMImageReader(000001DC61D2FED0) returned failure for request: vtkInformation (000001DC5F8E72A0)
  Debug: Off
  Modified Time: 207
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA
  FORWARD_DIRECTION: 0
  ALGORITHM_AFTER_FORWARD: 1
  FROM_OUTPUT_PORT: 0

I know the file is not corrupted as it works when I try to read it with pydicom.我知道该文件没有损坏,因为当我尝试使用 pydicom 读取它时它可以工作。 I tried to read the files with pydicom into a numpy array and then use the numpy_support.numpy_to_vtk to convert into a vtk array.我尝试使用 pydicom 将文件读入 numpy 数组,然后使用 numpy_support.numpy_to_vtk 转换为 vtk 数组。 But then I don't know how to insert those images into my vtk pipeline that uses the reader.GetOutputPort() to initiate the pipeline.但是我不知道如何将这些图像插入到使用 reader.GetOutputPort() 启动管道的 vtk 管道中。 Can someone help me to insert my DICOM file images which are VTK arrays into the VTK pipeline?有人可以帮我将作为 VTK 阵列的 DICOM 文件图像插入到 VTK 管道中吗?

This is my current code:这是我当前的代码:

# reading the data and converting it to VTK array using numpy_support
fileVolume = r"C:\Users\I_0001"
dicomVolume = pydicom.read_file(fileVolume)
shape = dicomVolume.pixel_array.shape
VTK_data = numpy_support.numpy_to_vtk(num_array=dicomVolume.pixel_array.ravel(), deep=True, array_type=vtk.VTK_FLOAT)


#need to insert VTK data here instead of using the vtk DICOM Image Reader
# Create the reader for the data.
reader = vtk.vtkDICOMImageReader()
reader.SetDirectoryName(r"C:\Users\I_0001")
reader.Update()

mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(reader.GetOutput())

使用VTKWithNumpy 例如通过@Nico Vuaille我联系能我numpy的数组转换成图像VTK对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM