Reference count with Python

Here is a short example how to use the Python pipeline:

def my_func():

my_pipeline=itk.pipeline()
MedianFilter=itk.MeanImageFilter.IUC2IUC2.New()
my_pipeline.connect(MedianFilter)
my_pipeline.expose("Radius")
thresholdFilter=itk.ThresholdImageFilter.IUC2.New()
my_pipeline.connect(thresholdFilter)
my_pipeline.expose("Lower")
return my_pipeline

my_pipeline = my_func()
my_pipeline.SetInput(im)
my_pipeline.SetRadius(5)
my_pipeline.SetLower(100)
my_pipeline.Update()
arr=itk.GetArrayFromImage(my_pipeline.GetOutput())

You could also derive the itk.pipeline class and create your pipeline inside the constructor __init__ of the new pipeline class like it is done in one ITK test.

1 Like