# Pythonic interface to ITK filters

**URL:** <https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106>\
**Category:** Community\
**Tags:** python\
**Created:** [July 9, 2018, 3:14pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106 "2018-07-09T15:14:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 9, 2018, 3:14pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/1 "2018-07-09T15:14:05Z")

</div>

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

[http://review.source.kitware.com/#/c/23560/](http://review.source.kitware.com/#/c/23560/)

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,

```auto
median_filter = itk.MedianImageFilter[ImageType, ImageType].New()
median_filter.SetInput(input_image)
median_filter.SetRadius(radius)
median_filter.Update()
result = median_filter.GetOutput()

```

we can just call

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

---

<div class="post-metadata">

**Author:** ![glemaitre](https://discourse.itk.org/user_avatar/discourse.itk.org/glemaitre/32/264_2.png) [@glemaitre](https://discourse.itk.org/u/glemaitre)\
**Post date:** [July 9, 2018, 3:45pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/2 "2018-07-09T15:45:14Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 9, 2018, 3:57pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/3 "2018-07-09T15:57:24Z")

</div>

@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. 🤝

---

<div class="post-metadata">

**Author:** ![gdevenyi](https://discourse.itk.org/user_avatar/discourse.itk.org/gdevenyi/32/355_2.png) [@gdevenyi](https://discourse.itk.org/u/gdevenyi)\
**Post date:** [July 19, 2018, 1:34am UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/4 "2018-07-19T01:34:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [July 19, 2018, 2:19pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/5 "2018-07-19T14:19:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gdevenyi](https://discourse.itk.org/user_avatar/discourse.itk.org/gdevenyi/32/355_2.png) [@gdevenyi](https://discourse.itk.org/u/gdevenyi)\
**Post date:** [July 19, 2018, 3:14pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/6 "2018-07-19T15:14:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 19, 2018, 4:18pm UTC](https://discourse.itk.org/t/pythonic-interface-to-itk-filters/1106/7 "2018-07-19T16:18:36Z")

</div>

> [@gdevenyi](#):
>
> Okay, I’ll ask the question slightly differently then, what are the major differences between SimpleITK and ITK’s pythonic interfaces?

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