# import 3D volume from ITK to VTK

**URL:** https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497
**Category:** Support
**Created:** [March 15, 2019, 6:25pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497 "2019-03-15T18:25:26Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 15, 2019, 6:25pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/1 "2019-03-15T18:25:26Z")

</div>

Hi guys! I’ve managed to read 200 DICOM files and use them to compose a volume…how can i pass this volume to VTK in order to actually see it?  
Thank u all for your answer 🙂

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [March 15, 2019, 7:11pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/2 "2019-03-15T19:11:53Z")

</div>

If you do not need to perform any image processing on your data, it is probably easier to use the `vtk::DICOMImageReader` class to [read your DICOM series](https://lorensen.github.io/VTKExamples/site/Cxx/IO/ReadDICOMSeries/).

Otherwise, if you “need” to use ITK to read the DICOM series, you could convert your `itk::Image` instance to a `vtk::ImageData` instance using the `itk::ImageToVTKImageFilter`, as shown in [this example](https://itk.org/ITKExamples/src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/Documentation.html).

In either case, using this example for your visualization purposes should be straightforward:

[https://lorensen.github.io/VTKExamples/site/Cxx/Medical/MedicalDemo4/](https://lorensen.github.io/VTKExamples/site/Cxx/Medical/MedicalDemo4/)

You should just plug the output of the `vtk::DICOMImageReader` or `vtk::ImageData` object to the `vtk::FixedPointVolumeRayCastMapper` instead of the `vtk::MetaImageReader` output used in the example.

HTH,  
JON HAITZ

---

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 15, 2019, 7:21pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/3 "2019-03-15T19:21:16Z")

</div>

Hi Jon and thank u for your answer. I have to use ITK because i have to segment the liver vessels and ‘‘highlight’’ them im my volume…so i need to perform segmentation in ITK and visualization in VTK and ‘pass’ the volume between the 2 (thank u again for your help).  
I wanted to create a bynary volume of my liver vessels and them ‘add’ it to my volume, do u know per chance any classes/examples that could help me?  
Thank u again for your help and support!  
Marco

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [March 15, 2019, 7:37pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/4 "2019-03-15T19:37:00Z")

</div>

@Marco_Festugato Please, try to honor the subject of the thread so that the discussion is kept healthy, and other users can find more easily answers and/or pointers to similar questions.

Now, the question you are asking is again related to image processing tools, such as ITK, so please post your question at the right discussion forum.

For the time being, you may find useful the following ITK examples:  
[https://itk.org/ITKExamples/src/Filtering/ImageFeature/SegmentBloodVessels/Documentation.html](https://itk.org/ITKExamples/src/Filtering/ImageFeature/SegmentBloodVessels/Documentation.html)  
[https://itk.org/ITKExamples/src/Nonunit/Review/SegmentBloodVesselsWithMultiScaleHessianBasedMeasure/Documentation.html](https://itk.org/ITKExamples/src/Nonunit/Review/SegmentBloodVesselsWithMultiScaleHessianBasedMeasure/Documentation.html)

Note that vessel segmentation is a complex task, and usually requires domain or image-specific development. So do not expect the above examples to provide you with a perfectly clean segmentation.

---

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 15, 2019, 7:40pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/5 "2019-03-15T19:40:18Z")

</div>

sorry, i thought it could be done with vtk too (im very new to both itk and vtk). Gonna post it there, thank u for your patience and excuse me!

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [March 16, 2019, 12:55am UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/6 "2019-03-16T00:55:35Z")

</div>

I would recommend not to start writing a viewer application from scratch. There are several open-source medical image computing application frameworks that take care of basics, such as DICOM import, image processing, segmentation, registration using ITK, visualization using VTK. You can use these application frameworks and add your custom functions as plugin modules. You may need to spend a few weeks or months to learn how to use, customize, and extend them, but you save several years of development time. For example [3D Slicer](https://www.slicer.org) and [MITK](http://mitk.org) are two well-established, general-purpose applications; but there are also a number of smaller, more specialized ones.

---

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 16, 2019, 4:22pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/7 "2019-03-16T16:22:25Z")

</div>

Hi Jon and thank u for your answer. I’ve tried as u said, here’s my code (I’ve used the example “Reading a 2D DICOM Series and Writing a Volume” in the ITKUserGuide to read my 200 dicom files in a volume):

…  
typedef itk::Image\< signed short, 3 \> ImageType;  
typedef itk::ImageToVTKImageFilter\< ImageType \> ConnectorType;  
ConnectorType::Pointer filter = ConnectorType::New();  
filter -\> SetInput( reader -\> GetOutput() );  
vtkImageData \* myvtkImageData = filter-\>GetOutput();  
…  
vtkFixedPointVolumeRayCastMapper \*mapper = vtkFixedPointVolumeRayCastMapper::New();  
mapper -\> SetInputConnection( myvtkImageData -\> GetOutputPort() );

In the last line I received an error telling me that ‘GetOutPort’ is not a member of ‘vtkImageData’. I’ve tried using ‘GetOutput’ but it gives me the same error…  
What should i do?  
Regards,  
Marco

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [March 16, 2019, 8:08pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/8 "2019-03-16T20:08:01Z")

</div>

Try `mapper ->SetInput( myvtkImageData );` instead of `mapper ->SetInputConnection( myvtkImageData -> GetOutputPort() );`

---

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 16, 2019, 8:19pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/9 "2019-03-16T20:19:01Z")

</div>

Hi Jon and thank u once again for your kind answer. I’ve tried but VS told me that ‘SetInput’ doesnt belong to the vtkFixedRayCastMapper, so i tried using ‘SetInputConnection’ but i received this error:

error C2664: ‘void vtkAlgorithm::SetInputConnection(vtkAlgorithmOutput \*)’: cannot convert argument 1 from ‘vtkImageData \*’ to ‘vtkAlgorithmOutput \*’

I really dont know how to do this…I think it’s should be something common to do while using itk/vtk, but i dont find anything yet on the internet that could help me ☹

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [March 16, 2019, 9:03pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/10 "2019-03-16T21:03:55Z")

</div>

You need to provide an output port (not an output data) as input.

Connecting ITK images to VTK pipine directly is not commonly done because it is rare that you start a new complex application from scratch and you need to deal with such low level details.

Also note that since VTK does not support oriented images (yet), if you simply connected ITK filters directly to a VTK visualization pipeline, then all non-axis aligned images would appear at incorrect position/orientation. In 3D Slicer, we use a custom class (vtkMRMLVolumeNode) that stores a vtkImageData and additional metadata (such as image orientation) and orientation is injected into the visualization pipeline at the actor level.

---

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 16, 2019, 9:30pm UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/11 "2019-03-16T21:30:39Z")

</div>

Hi Andras and thank u for your answer. Unfortunately for my project it is mandatory to visualize with VTK and i was thinking about using ITK to perform somo image processing before visualizing my volume…im stuck at this point because i dont know what class to use in order to ‘‘pass’’ my volume from ITK to VTK ☹

Do u know how could I pass an output port as input?

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [March 17, 2019, 2:59am UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/12 "2019-03-17T02:59:19Z")

</div>

@Marco_Festugato

> Try `mapper ->SetInput( myvtkImageData );` instead of `mapper ->SetInputConnection( myvtkImageData -> GetOutputPort() );`

Sorry, I meant `mapper->SetInputData( myvtkImageData )`.

But do pay attention to what Andras’ has mentioned.

---

<div class="post-metadata">

### Author: ![Marco\_Festugato](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco_festugato/32/327_2.png) [@Marco\_Festugato](https://discourse.vtk.org/u/Marco_Festugato)
#### Post date: [March 17, 2019, 8:13am UTC](https://discourse.vtk.org/t/import-3d-volume-from-itk-to-vtk/497/13 "2019-03-17T08:13:12Z")

</div>

Hi Jon and thank you for your answer. I’ve tried using ‘SetInputData’ and i didnt receive an error during the building with VS.  
Only, when i want to visualize my volume it opens a window telling me that my mapper (vtkFixedPointVolumeRayCastMapper) doesnt support ''cell scalars"…should I use an itkCastImageFilter before connecting my volume to my mapper?

:’((((
