Pythonic interface to ITK filters


(Matt McCormick) #1

A new patch is available to add a more Python interface to ITK filters in ITK 5:

This auto-generates a procedural, snake_case interface to ITK filters, i.e. anything that inherits from itk.ProcessObject. Instead of the Object-oriented interface,

median_filter = itk.MedianImageFilter[ImageType, ImageType].New()
result = median_filter.GetOutput()

we can just call

result = itk.median_image_filter(input_image, radius=radius)

This leverages the work by Gaetan Lehmann many years ago in the Python wrapping, which was recently updated and improve by @fbudin. Here the filter is implicitly updated and its output is returned if there is a single output, or the indexed outputs are returned as a tuple if there are multiple. The type of the filter is determined by the input_image type. Parameters that could be set on the object with SetParameterName can be specified with keyword arguments also in snake case, e.g. parameter_name.

@glemaitre @cdeepakroy

Importing image from array and axis reorder
(Guillaume Lemaitre) #2

This is actually looking great and what I had in mind at that time.
It seems that you are in SciPy so you might use the feedback of some Python user :slight_smile:

(Matt McCormick) #3

@glemaitre excellent. Yes, I am at the SciPy conference, and I will see if I can get some feedback.

If anyone in the community is at SciPy, I would be happy to meet with you. :handshake:

(Gabriel A. Devenyi) #4

How does this relate to SimpleITK’s python interface. I have been using that to avoid writing C++ code. Is this the supported interface going forward?

(Dave Chen) #5

We continue to work on and support SimpleITK. I’d suggest using which ever interface suits your needs better.

(Gabriel A. Devenyi) #6

Okay, I’ll ask the question slightly differently then, what are the major differences between SimpleITK and ITK’s pythonic interfaces?

(Matt McCormick) #7
  • For the procedural functions, SimpleITK has custom function names created per image filter that are CamelCase, e.g. sitk.Median versus the snake_case version of the corresponding ITK filter, e.g. itk.median_image_filter
  • Parameters for SimpleITK are often custom positional or camelCase, where parameters for ITK are the snake_case keyword arguments that correspond to the SetParameterName methods.
  • SimpleITK supports image filters. ITK’s Pythonic functions are anything that inherits from itk.ProjectObject, i.e. mesh filters, point set filters, path filters, image filters …

Should I switch from SimpleITK to Python ITK?
Should I switch from SimpleITK to Python ITK?