[Insight-users] how to use itkfastmarchingfilter in python

Charl P. Botha c.p.botha at ewi.tudelft.nl
Sat, 20 Mar 2004 16:06:18 +0100


xujf at sjtu.edu.cn wrote:

> xujf wrote:
>   Hi,
>   I want to use itkFastMarchingFilter in Python,but I meet some difficulty.this is part of my program:
>   .......
>   itkfastmarchingfilter=itkFastMarchingImageFilterF3F3_New()
>   seeds=itkFastMarchingImageFilter_NodeContainer_New()
>   node=itkFastMarchingImageFilter_NodeType_New()
>   #node.SetValue(0.0)
>   #node.SetIndex( )
>   seeds.Initialize()
>   seeds.InsertElement(0,node)
>   itkfastmarching.SetTrialPoints(seeds)
>   ..........
>   the sencond and the third lines are wrong.
> 
>   I don\'t know how to get a "NodeContainer" type and "NodeType"type in Python .
> 
> thanks in advance! 

You need something like this:
    # same dimension as image
    seedPosition = itk.itkIndex2()
    seedPosition.SetElement(0, int(sys.argv[3]))
    seedPosition.SetElement(1, int(sys.argv[4]))

    initialDistance = float(sys.argv[5])
    seedValue = - initialDistance
    node = itk.itkLevelSetNodeF2()
    node.SetValue(seedValue)
    node.SetIndex(seedPosition)

    seeds = itk.itkNodeContainerF2_New()
    seeds.Initialize()
    seeds.InsertElement(0, node)

This was taken from the GeodesicActiveContourFilter.py example from the
latest ITK CVS.  You need at least the ITK 1.6 branch for this to work
(or the latest CVS, of course).

-- 
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/