There is a C++ tutorial on how to convert between SimpleITK and ITK, but I’m struggling to translate it into Python.
In [14]: test_arr = np.ones((30, 30, 30), dtype=np.int16)
In [15]: test_arr[15, 15, 15] = 999
In [16]: sitk_image = sitk.GetImageFromArray(test_arr)
In [17]: sitk_image.GetPixelID()
Out[17]: 2
In [18]: itk_image = sitk_image.GetITKBase()
In [19]: itk_image
Out[19]: <Swig Object of type 'itk::DataObject *' at 0x7f6115837f30>
In [20]: itk_image.IsNull()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-ed3d70ad1fde> in <module>
----> 1 itk_image.IsNull()
AttributeError: 'SwigPyObject' object has no attribute 'IsNull'
In [22]: itk_arr = itk.array_from_image(itk_image)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-22-1ffbcbc9e438> in <module>
----> 1 itk_arr = itk.array_from_image(itk_image)
~/anaconda3/envs/dl/lib/python3.7/site-packages/itkExtras.py in GetArrayFromImage(image_or_filter, keep_axes, update)
255 """Get an array with the content of the image buffer
256 """
--> 257 return _GetArrayFromImage(image_or_filter, "GetArrayFromImage", keep_axes, update)
258
259 array_from_image = GetArrayFromImage
~/anaconda3/envs/dl/lib/python3.7/site-packages/itkExtras.py in _GetArrayFromImage(image_or_filter, function, keep_axes, update)
246 keys = [k for k in itk.PyBuffer.keys() if k[0] == output(image_or_filter).__class__]
247 if len(keys ) == 0:
--> 248 raise RuntimeError("No suitable template parameter can be found.")
249 ImageType = keys[0]
250 # Create a numpy array of the type of the input image
RuntimeError: No suitable template parameter can be found.
Could you please help me with this (and reverse, ITK -> SimpleITK) conversion?