ITK compilation options for PythonWrapper

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.
   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.
    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 :beers:

1 Like

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:

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

1 Like

Thanks @dzenanz :wink:
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?

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

Welcome to the ITK community @Stephan_Hahn1! :sunny:

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:

In [3]: itk.SymmetricEigenAnalysisImageFilter.GetTypes()
<itkTemplate itk::SymmetricEigenAnalysisImageFilter>
Options:
  [<class 'itk.itkImagePython.itkImageSSRTD22'>,]
  [<class 'itk.itkImagePython.itkImageSSRTD33'>,]
  [<class 'itk.itkImagePython.itkImageSSRTD44'>,]
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.

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:

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

eigen_filter = itk.SymmetricEigenAnalysisImageFilter.New(hessian_matrix)
eigen_filter.SetDimension(3)
eigen_filter.Update()
eigen_values = eigen_filter.GetOutput()
1 Like

thanks a lot Matt :slight_smile:
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

1 Like