# Build ITKPython module with additional supported data types

**URL:** https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042
**Category:** Engineering
**Tags:** python, cmake
**Created:** [April 16, 2021, 10:56am UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042 "2021-04-16T10:56:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Reimelt](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@Alex\_Reimelt](https://discourse.itk.org/u/Alex_Reimelt)
#### Post date: [April 16, 2021, 10:56am UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/1 "2021-04-16T10:56:39Z")

</div>

Dear ITK community,

after generating radially distorted images of lung tissue for my PhD project with ITKPython, I have realized that multiple filters I use do not support certain ITK data types. In order to solve this issue, I built the ITK python module myself and selected the previously missing ITK data types to be supported. However, after running a test script, the situation did not change. This is my test script that is supposed to show the supported data types of the NearestneighbourInterpolateImageFunction. After the build, itk.F should be supported as well:

`import itk

x = itk.NearestNeighborInterpolateImageFunction.GetTypes()  
print(x)`

However, this is the output I receive:

`  
Options:  
[\<class ‘itk.itkImagePython.itkImageD2’\>,]  
[\<class ‘itk.itkImagePython.itkImageD3’\>,]  
[\<class ‘itk.itkImagePython.itkImageF2’\>,]  
[\<class ‘itk.itkImagePython.itkImageF3’\>,]  
[\<class ‘itk.itkImagePython.itkImageSC2’\>,]  
[\<class ‘itk.itkImagePython.itkImageSC3’\>,]  
[\<class ‘itk.itkImagePython.itkImageSS2’\>,]  
[\<class ‘itk.itkImagePython.itkImageSS3’\>,]  
[\<class ‘itk.itkImagePython.itkImageUC2’\>,]  
[\<class ‘itk.itkImagePython.itkImageUC3’\>,]  
[\<class ‘itk.itkImagePython.itkImageULL2’\>,]  
[\<class ‘itk.itkImagePython.itkImageULL3’\>,]  
[\<class ‘itk.itkImagePython.itkImageUS2’\>,]  
[\<class ‘itk.itkImagePython.itkImageUS3’\>,]  
None

Process finished with exit code 0`

For the build process, this was my knowledge souce:  
[https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch3.html#x39-440003.7](https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch3.html#x39-440003.7)

The error message of my original script for the radial image warping is the following:  
`Traceback (most recent call last): File "./Test_Displacement.py", line 49, in <module> interpolator = itk.NearestNeighborInterpolateImageFunction[ImageType, itk.F].New() File "/home/reimelta/.local/lib/python2.7/site-packages/itkTemplate.py", line 340, in __getitem__ raise TemplateTypeError(self, tuple(cleanParameters)) itkTemplate.TemplateTypeError: itk.NearestNeighborInterpolateImageFunction is not wrapped for input type `itk.Image[[itk.US](http://itk.US),3], itk.F`.

To limit the size of the package, only a limited number of  
types are available in ITK Python. To print the supported  
types, run the following command in your python environment:

```
itk.NearestNeighborInterpolateImageFunction.GetTypes()

```

Possible solutions:

- If you are an application user:  
\*\* Convert your input image into a supported format (see below).  
\*\* Contact developer to report the issue.

- If you are an application developer, force input images to be  
loaded in a supported pixel type.

- (Advanced) If you are an application developer, build ITK Python yourself and  
turned to `ON` the corresponding CMake option to wrap the pixel type or image  
dimension you need. When configuring ITK with CMake, you can set  
`ITK_WRAP_${type}` (replace ${type} with appropriate pixel type such as  
`double`). If you need to support images with 4 or 5 dimensions, you can add  
these dimensions to the list of dimensions in the CMake variable  
`ITK_WRAP_IMAGE_DIMS`.

Supported input types:

itk.Image[itk.SS,2]  
itk.Image[itk.UC,2]  
itk.Image[[itk.US](http://itk.US),2]  
itk.Image[itk.F,2]  
itk.Image[itk.SS,3]  
itk.Image[itk.UC,3]  
itk.Image[[itk.US](http://itk.US),3]  
itk.Image[itk.F,3]`

My question is: what could be the most common errors during a special build of the ITKPython module?

Thank you in advance!

Alex Reimelt

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [April 16, 2021, 11:10am UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/2 "2021-04-16T11:10:16Z")

</div>

Hi Alex,

`itk.F` corresponds to a PixelType (`float`).  
It’s the default, and that filter is already wrapped for 2D and 3D float images:

> [@Alex\_Reimelt](#):
>
> [\<class ‘itk.itkImagePython.itkImageF2’\>,]  
> [\<class ‘itk.itkImagePython.itkImageF3’\>,]

It seems ok to me, what were you expecting?

---

<div class="post-metadata">

### Author: ![Alex\_Reimelt](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@Alex\_Reimelt](https://discourse.itk.org/u/Alex_Reimelt)
#### Post date: [April 16, 2021, 11:38am UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/3 "2021-04-16T11:38:50Z")

</div>

Hi Pablo,

thank you for your quick response! Indeed, now more ImageTypes are supported, but the TCoordRep is still itkCType double in every combination. This is the value we wanted to change to float (see updated question).

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [April 16, 2021, 1:17pm UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/4 "2021-04-16T13:17:19Z")

</div>

`itkNearestNeighborInterpolateImageFunction` wrap file is here:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/047fa6934ac32711d1d7b84fa6eb81c72db01960/Modules/Core/ImageFunction/wrapping/itkNearestNeighborInterpolateImageFunction.wrap#L4>

The second parameter `TCoordRep` is fixed to `double`, which is the default in the C++ side.

> <https://github.com/InsightSoftwareConsortium/ITK/blob/87451e3de3acb2903c1d46b99ff5f03d324e02bb/Modules/Core/ImageFunction/include/itkNearestNeighborInterpolateImageFunction.h#L38-L40>

If you want to support `float`, you first need to check that the base class `InterpolateImageFunction` is wrapped for `float`, which is the case!

> <https://github.com/InsightSoftwareConsortium/ITK/blob/87451e3de3acb2903c1d46b99ff5f03d324e02bb/Modules/Core/ImageFunction/wrapping/itkInterpolateImageFunction.wrap#L6>

And then, **add** to `itkNearestNeighborInterpolateImageFunction.wrap:5`

```cpp
  itk_wrap_template("${ITKM_I${t}${d}}${ITKM_F}" "${ITKT_I${t}${d}},${ITKT_F}")

```

After you added that line, and test that it works, you might want to close the circle, and contribute to ITK, [opening a pull-request](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md) with the change. 🥳

---

<div class="post-metadata">

### Author: ![Alex\_Reimelt](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@Alex\_Reimelt](https://discourse.itk.org/u/Alex_Reimelt)
#### Post date: [April 16, 2021, 1:19pm UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/5 "2021-04-16T13:19:42Z")

</div>

Thank you! I will try it out.

---

<div class="post-metadata">

### Author: ![Alex\_Reimelt](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@Alex\_Reimelt](https://discourse.itk.org/u/Alex_Reimelt)
#### Post date: [April 19, 2021, 3:30pm UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/6 "2021-04-19T15:30:07Z")

</div>

Hi Pablo,

it partly worked out. But now, there still seems to be a remaining problem with the WarpImageFilter which expects itk.D. This is the current error message:

```
File "Test_Displacement.py", line 51, in <module>
warpFilter.SetInterpolator(interpolator)
TypeError: in method 'itkWarpImageFilterIUS3IUS3IVF33_SetInterpolator', argument 2 of type 'itkInterpolateImageFunctionIUS3D *'
```

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [April 20, 2021, 9:01am UTC](https://discourse.itk.org/t/build-itkpython-module-with-additional-supported-data-types/4042/7 "2021-04-20T09:01:59Z")

</div>

Yes, that happens. It seems way easier that you cast your TCoordRep from float32 to float (double) and don’t deal with extra wrapping types.

Or, you keep adding the float wrap to all the filters used in your pipeline.

First option seems easier.
