[Insight-users] wrapITK+Python2.7+Visual Studio 2010

Matt McCormick matt.mccormick at kitware.com
Sat Aug 4 21:02:32 EDT 2012


Hi Manuel,

> I am relatively new in working with ITK, VTK and Python and this question
> may be a little bit silly.

Welcome to the community!  These seem like well researched questions,
and they are welcome.

 but I am having some troubles in wrapping the ITK
> to Python.

Sorry for the difficulties.

 I first started using Cmake to Configure both CableSwig and ITK
> for Visual Studio 10. I basically followed the tutorial in the website:
>
> http://www.itk.org/Wiki/ITK/Tutorials
>
> After performing all the steps I was unable to build successfully all the
> projects within ITK. I have tried to build CableSwig outside and inside the
> ITK as was suggested in the website:
>
> http://www.itk.org/ITK/resources/CableSwig.html
>
> but unsuccessfully.

CableSwig is no longer required for Wrapping with ITKv4.  I have
corrected some of the wiki pages.

I finally gave up and tried to use the ITK with Python
> Wrapping Installer:
>
> http://farsight-toolkit.org/wiki/FARSIGHT_Tutorials/Just_Installing_Software

This is out-of-date -- it points to an old ITKv3 installer.
>
> by simply installing it I have access to the “.py” files with the ITK
> wrapped functions. I also added a “WrapITK.pth” to the site-packages folder
> of the python release that I am using and it worked. Currently I have
> something like this:
>
> ·         $Project Folder$\Python27\Lib\site-packages\ WrapITK.pth
>
> ·         $Project Folder$\InsightToolkit
>
> Where the “InsightToolkit” was the target installation folder of the ITK
> with Python Wrapping Installer.
>
> The problem is I am capable of importing ITK to Python, whether using the
> command line or any other IDE, however I think it is not assumed as a Python
> package. For instance:
>
> // Simple program for ITK image read/write in Python
>
> #!/usr/bin/env python
>
> import itk
>
> from sys import argv
>
> pixelType = itk.UC
>
> imageType = itk.Image[pixelType, 2]
>
> readerType = itk.ImageFileReader[imageType]
>
> writerType = itk.ImageFileWriter[imageType]
>
> reader = readerType.New()
>
> writer = writerType.New()
>
> reader.SetFileName( argv[1] )
>
> writer.SetFileName( argv[2] )
>
> writer.SetInput( reader.GetOutput() )
>
> writer.Update()
>
>
> http://www.vtk.org/Wiki/ITK/Release_4/Wrapping/Examples
>
> I am capable of doing:
>
> pixelType = itkTypes.UC
>
> so I am capable of recognizing itkBase, itkConfig, itkLazy, itkTypes,
> itkExtras, os, sys but I am unable to do the second line
>
> imageType = itk.Image[pixelType, 2]
>
>
>
> What I get from the Python command line is something like this:
>
> Traceback (most recent call last): File "<pyshell#3>", line 1, in <module>
> imageType = itk.Image[pixelType,2]
>
> File "... \InsightToolkit\lib\InsightToolkit\WrapITK\Python\itkLazy.py",
> line 18, in __getattribute__ itkBase.LoadModule(module, namespace)
>
> File "...\InsightToolkit\lib\InsightToolkit\WrapITK\Python\itkBase.py", line
> 24, in LoadModule swig.__dict__.update(this_module.swig.__dict__)
> AttributeError: 'module' object has no attribute 'swig'
>
>

You will need the ITKv4 wrapping to use this example.

Hope this helps,
Matt


More information about the Insight-users mailing list