# How to use VTK\_array in VTK pipeline (Python)?

**URL:** https://discourse.vtk.org/t/how-to-use-vtk-array-in-vtk-pipeline-python/7074
**Category:** Support
**Created:** [November 4, 2021, 12:17pm UTC](https://discourse.vtk.org/t/how-to-use-vtk-array-in-vtk-pipeline-python/7074 "2021-11-04T12:17:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![user\_42](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@user\_42](https://discourse.vtk.org/u/user_42)
#### Post date: [November 4, 2021, 12:17pm UTC](https://discourse.vtk.org/t/how-to-use-vtk-array-in-vtk-pipeline-python/7074/1 "2021-11-04T12:17:39Z")

</div>

I am new to `vtk` and am trying to do volume rendering with a DICOM file.

When I try to read the DICOM file using VTK with the following code:

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

```

I get the following error:

```auto
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. 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. But then I don’t know how to insert those images into my vtk pipeline that uses the reader.GetOutputPort() to initiate the pipeline. **Can someone help me to insert my DICOM file images which are VTK arrays into the VTK pipeline?**

This is my current code:

```auto
# 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())

```
