# ITK compilation options for PythonWrapper

**URL:** https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798
**Category:** Beginner Questions
**Tags:** python, simpleitk
**Created:** [January 26, 2021, 9:24am UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798 "2021-01-26T09:24:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Stephan\_Hahn1](https://discourse.itk.org/user_avatar/discourse.itk.org/stephan_hahn1/32/1871_2.png) [@Stephan\_Hahn1](https://discourse.itk.org/u/Stephan_Hahn1)
#### Post date: [January 26, 2021, 9:24am UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798/1 "2021-01-26T09:24:17Z")

</div>

Hi everyone,

I am using the `hessian_recursive_gaussian_image_filter` method from ITK wrapper in python. But I am facing 2 related problems:

1. My IO pipeline is based on SITK and I am transforming SITK to ITK using this [topic](https://discourse.itk.org/t/in-python-how-to-convert-between-simpleitk-and-itk-images/1922/2).

```auto
   itk_image= itk.GetImageFromArray(sitk.GetArrayFromImage(sitk_image), is_vector = sitk_image.GetNumberOfComponentsPerPixel()>1)
   output.SetSpacing(sitk_image.GetSpacing())
   output.SetOrigin(sitk_image.GetOrigin())
   output.SetDirection(itk.GetMatrixFromArray(np.reshape(np.array(sitk_image.GetDirection()), [len(sitk_image.GetSize())]*2)))

```

1. I am using `hessian_recursive_gaussian_image_filter` and `SymmetricEigenAnalysisImageFilter` to extract the hessian matrix and the eigen values.

```auto
    hessian_matrix = itk.hessian_recursive_gaussian_image_filter(get_itk_from_sitk(sitk_image), sigma=3, normalize_across_scale=True)
    eigen_filter = itk.SymmetricEigenAnalysisImageFilter[itk.D].New(hessian_matrix)
    eigen_filter.OrderEigenValuesBy()
    eigen_filter.SetDimension(3)
    eigen_filter.Update()
    eigen_values = eigen_filter.GetOutput()

```

The hessian\_matrix is a vector with PixelID Double and dimension 6. Actually the eigen output error is :

`itkTemplate.TemplateTypeError: itk.SymmetricEigenAnalysisImageFilter is not wrapped for input type 'itk.D'.`.

And the sitk\_to\_itk method output error also when I give the hessian vector as input:  
`itkTemplate.TemplateTypeError: itk.Image is not wrapped for input type 'itk.D, int'.`

I have re-code all the filters in numpy and it is working (using the ArrayView from itk/sitk). But actually, I would like to try ITK filters. I should probably compile ITK with python wrapper ON. I have seen that environment variables must be added into CMAKE (ITK\_WRAP\_ and ITK\_WRAP\_IMAGE\_DIMS) . But it is not clear which variable name to put in SITK. And resources needed to compile it?

thanks in advance for your help 🍻

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 26, 2021, 2:29pm UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798/2 "2021-01-26T14:29:40Z")

</div>

If you configure ITK or SimpleITK using CMake-GUI or ccmake, you will be able to see the complete list of options (assuming you turn on advanced variables). Here is a screenshot:

 ![Screenshot 2021-01-26 09.27.05](https://discourse.itk.org/uploads/default/original/2X/5/5aa7e0fdce21ea9ae733da0ee5fd46a64c50669e.png)

Regarding absence of wrapping for SymmetricEigenAnalysisImageFilter, maybe try instantiating with `itk.F`, or enable wrapping of double type (CMake option `ITK_WRAP_double`)?

---

<div class="post-metadata">

### Author: ![Stephan\_Hahn1](https://discourse.itk.org/user_avatar/discourse.itk.org/stephan_hahn1/32/1871_2.png) [@Stephan\_Hahn1](https://discourse.itk.org/u/Stephan_Hahn1)
#### Post date: [January 26, 2021, 2:37pm UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798/3 "2021-01-26T14:37:42Z")

</div>

Thanks @dzenanz 😉  
Yes I did that for SimpleITK + SimpleElastix and after some tricks it was working.  
I have tested itk.F and that gives me the same error. I will try to compile with ITK\_WRAP\_DOUBLE.  
And concerning WRAP\_VECTOR\_COMPONENTS, should I compile for 2;3;4;6 as I have 6 components for the hessian?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 26, 2021, 2:46pm UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798/4 "2021-01-26T14:46:06Z")

</div>

> [@Stephan\_Hahn1](#):
>
> And concerning WRAP\_VECTOR\_COMPONENTS, should I compile for 2;3;4;6 as I have 6 components for the hessian?

I don’t think that is the issue, but you can try.

---

<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: [February 1, 2021, 7:58pm UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798/5 "2021-02-01T19:58:07Z")

</div>

Welcome to the ITK community @Stephan_Hahn1! ☀

> [@Stephan\_Hahn1](#):
>
> itk.SymmetricEigenAnalysisImageFilter is not wrapped for input type ‘itk.D’

The `itk.SymmetricEigenAnalysisImageFilter` operates on images of symmetric second rank tensors (a hessian matrix is a symmetric second rank tensor). It is wrapped for this type instead of double’s. We can see this from:

```auto
In [3]: itk.SymmetricEigenAnalysisImageFilter.GetTypes()
<itkTemplate itk::SymmetricEigenAnalysisImageFilter>
Options:
  [<class 'itk.itkImagePython.itkImageSSRTD22'>,]
  [<class 'itk.itkImagePython.itkImageSSRTD33'>,]
  [<class 'itk.itkImagePython.itkImageSSRTD44'>,]

```

```auto
In [7]: itk.template(itk.itkImagePython.itkImageSSRTD33)
Out[7]: 
(<itkTemplate itk::Image>,
 (itk.itkSymmetricSecondRankTensorPython.itkSymmetricSecondRankTensorD3, 3))

```

However, if you use the functional, Pythonic call to the ITK filter, it picks the correct filter for you based on the input type.

```auto
In [10]: hessian_matrix = itk.hessian_recursive_gaussian_image_filter(image)

In [11]: type(hessian_matrix)
Out[11]: itk.itkImagePython.itkImageSSRTD33

In[12]: eigen_values = itk.symmetric_eigen_analysis_image_filter(hessian_matrix, dimension=3)

```

Alternatively, with the object oriented interface:

```auto
eigen_filter = itk.SymmetricEigenAnalysisImageFilter[type(hessian_matrix)].New(hessian_matrix)
eigen_filter.SetInput(hessian_matrix)
eigen_filter.SetDimension(3)
eigen_filter.Update()
eigen_values = eigen_filter.GetOutput()

```

or

```auto
eigen_filter = itk.SymmetricEigenAnalysisImageFilter.New(hessian_matrix)
eigen_filter.SetDimension(3)
eigen_filter.Update()
eigen_values = eigen_filter.GetOutput()

```

---

<div class="post-metadata">

### Author: ![Stephan\_Hahn1](https://discourse.itk.org/user_avatar/discourse.itk.org/stephan_hahn1/32/1871_2.png) [@Stephan\_Hahn1](https://discourse.itk.org/u/Stephan_Hahn1)
#### Post date: [February 2, 2021, 10:08am UTC](https://discourse.itk.org/t/itk-compilation-options-for-pythonwrapper/3798/6 "2021-02-02T10:08:19Z")

</div>

thanks a lot Matt 🙂  
Actually, I coded a generic data format to use easily multiple libraries (sitk, numpy+ scipy, skimage, itk, opencv) for image processing. I think that the bugs come from the transfer from one data format to the other one. I will refactor a little bit to handle this issue. thanks for your code
