[ITK] [ITK-users] Python wrapping issue

Paolo Zaffino p.zaffino at yahoo.it
Wed Oct 14 11:17:38 EDT 2015


Hi Matt and hi all,
thank you very much for your help.
Unfortunately python crashes (segmentation fault) at the final phase of 
these three examples (basically when I try to create an image):

 1. import itk
    Dimension = 3
    PixelType = itk.F
    ImageType = itk.Image[PixelType, Dimension]

 2. import itk
    img = itk.Image.F3.New()

 3. import itk
    pixelType = itk.UC
    imageType = itk.Image[pixelType, 2]

Any idea?
Thank you very much again.

Best.
Paolo



On 14/10/2015 16:48, Matt McCormick wrote:
> Hi Paolo,
>
> Lassi has some good suggestions. Some additional information:
>
> If you use ITK Git master [1], the Python wrapping builds in half the
> time as ITK 4.8.
>
> To create a histogram matching filter, the preferred syntax is:
>
>    import itk
>    Dimension = 3
>    PixelType = itk.F
>    ImageType = itk.Image[PixelType, Dimension]
>    histogramMatching = itk.HistogramMatchingImageFilter[ImageType,
> ImageType].New()
>
> Hope this helps,
> Matt
>
> [1] http://www.itk.org/Wiki/ITK/Git
>
> On Wed, Oct 14, 2015 at 5:27 AM, Paavolainen, Lassi
> <lassi.paavolainen at jyu.fi> wrote:
>> Hi Paolo,
>>
>> Why you want to import itkImagePython instead of just itk?
>>
>> import itk
>> img = itk.Image.F3.New()
>>
>> should work as previously. Notice that
>> itk.HistogramMatchingImageFilter()
>> would not work in any case since you need to define the types as well.
>>
>> The modular design of ITK 4 should not have effected the interface of ITK
>> Python wrappings in anyway. If I'm wrong then maybe someone can correct me.
>>
>> So I would first check that you are able to import itk and load some filter.
>> If not, then check that all shared libs are in search path.
>>
>> Cheers,
>> Lassi
>>
>> ________________________________
>> From: Insight-users [insight-users-bounces at itk.org] on behalf of Paolo
>> Zaffino [p.zaffino at yahoo.it]
>> Sent: Wednesday, October 14, 2015 11:51
>> To: insight-users at itk.org
>> Subject: [ITK-users] Python wrapping issue
>>
>> Dear ITK community,
>> I compiled ITK 4.8 into an Ubuntu 14.04 machine enabling also the python
>> wrapping.
>> Compiling the code took really a while and I had to restart the make phase
>> more than one time since it crashed without any apparently reason.
>> Finally when the make step was over I executed the make install command.
>>
>> If I open ipython and I type "import itkImagePython" it returns
>>
>> ---------------------------------------------------------------------------
>> ImportError                               Traceback (most recent call last)
>> <ipython-input-1-dfd82b0a3e37> in <module>()
>> ----> 1 import itkImagePython
>>
>> /usr/local/lib/ITK-4.8/Python/itkImagePython.py in <module>()
>>       30                 fp.close()
>>       31             return _mod
>> ---> 32     _itkImagePython = swig_import_helper()
>>       33     del swig_import_helper
>>       34 else:
>>
>> /usr/local/lib/ITK-4.8/Python/itkImagePython.py in swig_import_helper()
>>       22             fp, pathname, description =
>> imp.find_module('_itkImagePython', [dirname(__file__)])
>>       23         except ImportError:
>> ---> 24             import _itkImagePython
>>       25             return _itkImagePython
>>       26         if fp is not None:
>>
>> ImportError: No module named _itkImagePython
>>
>> but if I run "import ITKRegionGrowingPython" it works.
>> In addition, after importing ITKRegionGrowingPython also itkImagePython
>> works!
>>
>> I think the path is correctly set, since I see
>> /usr/local/lib/ITK-4.8/Python.
>> I also noted that in the "compiledFolder/lib" I see:
>>
>> ITKRegionGrowingPython.py and _ITKRegionGrowingPython.so
>> itkImagePython.py but NOT _itkImagePython.so
>>
>>
>> Do you have any idea?
>>
>> Furthermore, is it the syntax itk.something still valid or it has been
>> replaced by separate submodules?
>> Because if I run
>> hm=itk.HistogramMatchingImageFilter()
>> I get
>> UnboundLocalError: local variable 'module' referenced before assignment
>>
>> Thank you very much.
>> Regards.
>>
>> Paolo
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/insight-users
>>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20151014/c4ad790e/attachment.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list