import 3D volume from ITK to VTK

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 :slight_smile:

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.

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.

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

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.


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_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:

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.

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!

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 and MITK are two well-established, general-purpose applications; but there are also a number of smaller, more specialized ones.

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?

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

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 :frowning:

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.

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 :frowning:

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


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.

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?