[Insight-users] Re: ITK with Python help

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Wed Sep 27 06:22:28 EDT 2006


Hi,


Gaetan


On Mon, 25 Sep 2006 21:10:06 +0200, <m6chung at ucsd.edu> wrote:

> Hi Gaetan Lehmann
>
> I'm currently working with ITK wrapped in python with the built in
> wrappers. I'm having some troubles with getting my program to work and I
> was wondering if you could spare some time to help.
>
> My objective is to read an image and get a list of pixel locations where
> the pixel value is some specific value.
>
> I have encountered two main problems so far: 1. python wrapped ITK does
> not have any iterators that keep track of pixel index. Maybe this is a
> false assumption, but I have not been able to find any.

I don't think there is any iterator with the current wrappers.
It is possible to have them with WrapITK, but it require to patch ITK  
itself because the oeprator++() method is not available. There is some  
patch in patch/optional to do that.
Hopefully, cableswig should be updated soon. It will let us easily use the  
iterators in python :-)

> And 2. using the GetPixel command returns a pointer, which python cannot
> understand. I've read many of your works online and I understand that
> maybe this issue can be resolved by wrapping ITK with WrapITK... but is
> there another workaround perhaps?
>

Just add

%typemap(out) unsigned char &, const unsigned char &
   {$result = SWIG_FromUnsignedChar( *$1 );}
%typemap(out)  signed char &, const signed char &
   {$result = SWIG_FromSignedChar( *$1 );}
%typemap(out)  unsigned short &, const unsigned short &
   {$result = SWIG_FromUnsignedShort( *$1 );}
%typemap(out)  signed short &, const signed short &
   {$result = SWIG_FromShort( *$1 );}
%typemap(out)  unsigned int &, const unsigned int &, signed int &, const  
signed int &
   {$result = SWIG_FromInt( *$1 );}
%typemap(out)  signed long &, const signed long &, unsigned long &, const  
unsigned long &
   {$result = SWIG_FromLong( *$1 );}
%typemap(out) float &, const float &, double &, const double &
   {$result = SWIG_FromDouble( *$1 );}

to your itk.swg file, and it should work.
That being said, you should think to use WrapITK. It really comes with  
lots of improvements, and is now in ITK cvs. Just check out ITK cvs, and  
set USE_WRAP_ITK to ON.

Please let us know if you have any problem

Regards,

Gaetan

> If you can offer any advice, or propose another algorithm for my
> objective, that would be most appreciated.
>
> Thanks for your time,
> Michael Chung.



-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr


More information about the Insight-users mailing list