[Insight-users] WrapITK and Index
Zachary Pincus
zpincus at stanford.edu
Wed Apr 12 16:29:51 EDT 2006
Hi Vincent -
Actually, you can do plenty with an ITK Index from python. Especially
if you have applied the optional patches.
In [1]: import itk
In [2]: i = itk.Index[2]()
In [3]: dir(i)
Out[3]:
['Fill',
'GetBasisIndex',
'GetElement',
'GetIndex',
'GetIndexDimension',
'SetElement',
'SetIndex',
...
'__getitem__',
...
'__len__',
...
'__setitem__']
So we can see that the index instance has useful methods like
GetElement. (Looking at the documentation for Index would also have
showed this: http://www.itk.org/Doxygen/html/classitk_1_1Index.html )
Also, if you applied the optional patches, the Index class has python
sequence methods like __getitem__ and __len__, so you can do things
like:
len(i)
x = i[0]
p = list(i)
the latter of which will turn the index into a full-fledged list.
Also, when I run:
print i
I get:
<Index [0, 0]>
Which is much nicer than what you report below. Did you install the
optional ITK patches? If not, you should, because they really help
things. (One of my longer-term projects is to re-write a big chunk of
WrapITK so that these patches are not necessary. But this is not
something I can do right now.)
Zach
On Apr 12, 2006, at 7:51 AM, Vincent Page wrote:
> Hi,
>
> I now want to print the index of max and index of min
> in an image...
> So what I do is :
>
> ----------------------------
> affiche = itk.MinimumMaximumImageCalculator.IF2.New(masque)
> affiche.Compute()
> indexMax = affiche.GetIndexOfMaximum()
> print indexMax
> print affiche.GetMaximum()
> indexMin = affiche.GetIndexOfMinimum()
> print indexMin
> ---------------------------
>
> And the result is :
> <C itk::Index<(2)> instance at _48a6ea0200000000_p_itk__IndexT2_t>
> 3.40282346639e+38
> <C itk::Index<(2)> instance at _38a6ea0200000000_p_itk__IndexT2_t>
> -0.0313725508749
>
> ============
> Looks like another trouble I had, when WrapITK didn't transform
> the results of a function into something usable by python.
> Here, I guess that indexMin is some kind of a string
> type (indexMin) gives
> <class 'itkIndex.itkIndex2Ptr'>
>
> Did I miss something ?
>
> Vincent.
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list