[Insight-users] accessing vector value from python

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Wed Apr 5 09:01:51 EDT 2006


Hi Eduardo,

You're doing nothing wrong, this feature is just not implemented in the  
current python wrappers.

WrapITK support that, and will also let you use python sequences to acces  
to your data:

15> i = itk.Image.VF22.New()

16> i.SetRegions(10)

17> i.Allocate()

18> i.GetPixel([0,2])
18> <C itk::Vector<(float,2)> instance at  
_84c16a09_p_itk__VectorTfloat_2_t>

19> i.GetPixel([0,2])[0]
19> 2.7494886334130231e-33

20> i.SetPixel(0, 1)

21> i.GetPixel(0)[1]
21> 1.0

You can get WrapITK from  
http://voxel.jouy.inra.fr/darcs/contrib-itk/WrapITK/WrapITK.tar.gz.
An article have also been submited to the insight journal  
(http://insight-journal.org). It describe the new features which comes  
with WrapITK.

Please try it, and send us your comment about what you find good or not

Regards,

Gaetan


On Wed, 05 Apr 2006 14:45:28 +0200, Eduardo Suarez <eduardo at ctm.ulpgc.es>  
wrote:

> When i run this code, i finally get a string. What am i doing wrong?
>
> Thanks,
> -Eduardo
>
> import InsightToolkit as itk
> reader = itk.itkImageFileReaderVF2_New()
> reader.SetFileName('output.mhd')
> reader.Update()
> image = reader.GetOutput()
> image
>     <C itk::Image<(itk::Vector<(float,2)>,2)> instance at
>     _d005d208_p_itk__ImageTitk__VectorTfloat_2_t_2_t>
> ind=itk.itkIndex2()
> ind.SetElement(0, 0)
> ind.SetElement(1, 0)
> pix=image.GetPixel(ind)
> pix
>     '_0441d308_p_itk__VectorTfloat_2_t'
> pix.__class__
>     <type 'str'>



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