[Insight-users] ITK to VTK for 4D images

Mathieu Stumpf mathieu.stumpf at etu.unistra.fr
Mon Apr 23 08:22:52 EDT 2012


Hello,

I'm seeking information to open (with python) a 4D image with ITK and
visualize it with the help of VTK.

I followed several tracks but nothing which works until now.

# ConnectVTKITK used in the Examples directory

I first found an example using ConnectVTKITK  in
${itk-src}/Examples/Visualization/CannyEdgeDetectionImageFilterConnectVTKITK.py

I didn't manage to install InsightApplications yet. InsightApplications
provides ConnectVTKITK, but here is my problem :

 CMake Warning at ConnectVTKITK/CMakeLists.txt:11 (FIND_PACKAGE):
   Could not find module FindCableSwig.cmake or a configuration file for
   package CableSwig.

   Adjust CMAKE_MODULE_PATH to find FindCableSwig.cmake or set CableSwig_DIR
   to the directory containing a CMake configuration file for CableSwig.  The
   file will have one of the following names:

     CableSwigConfig.cmake
     cableswig-config.cmake

I downloaded CableSwig, but didn't find such a file.

Moreover the ITK documentation say[1] :
        Note that not all image types will work correctly. VTK will only
        support images of 1, 2, or 3 dimensions. Scalar value types can
        be one of: float, double, char, unsigned char, short, unsigned
        short, int, unsigned int, long, unsigned long.
        
As I need to visualize 4D images, maybe it's not the way to go anyway.
Is the documentation right? As far as I understand, VTK enable to
visualize tractographies and so on, so does it mean that it's the
conversion which is not provided through this way ?
        
[1] http://www.itk.org/Doxygen/html/classitk_1_1VTKImageExport.html

# Conversion from a C++ wiki example

Following a wiki page[2], I wrote a python code which provide a vtk
image with itk filters :
[2] http://www.itk.org/Wiki/ITK/Examples/IO/ImageToVTKImageFilter

        InputImageType = itk.Image.SS3
        reader = itk.ImageFileReader[InputImageType].New()
        reader.SetFileName(str(file_path)) # str() to avoid a wrapper bug
        
        # itk->vtk conversion 
        connector = itk.ImageToVTKImageFilter[InputImageType].New()
        connector.SetInput(reader.GetOutput())
        connector.Update()
        self.vtk_image = connector.GetOutput()

Well, it provide a vtkImageData (I checked with a print), but using it
instead of my previous solution using SimpleITK make my application
crash, without any debugging information. The previous working solution
being :

        self.sitk_image = sitk.ReadImage(str(file_path) )
        self.numpy_img = sitk.GetArrayFromImage( self.sitk_image ) 
        n2vtk = vtkImageImportFromArray() # Converter
        n2vtk.SetArray(self.numpy_img)
        n2vtk.Update()
        self.vtk_image = n2vtk.GetOutput()

I welcome any suggestion
kind regards,
mathieu





More information about the Insight-users mailing list