Filter does not support casting from casting vector of 8-bit unsigned integer to 32-bit float
Hi,
I'm trying to run the affine registration example: https://simpleelastix.readthedocs.io/AffineRegistration.html I've downloaded the brain images from the page (png format), but when I try to run the example code, I get:
File "./register.py", line 9, in <module>
elastixImageFilter.Execute()
File "/home/francisr/registration/venv/lib/python3.5/site-packages/SimpleITK-1.2.0rc2.dev1162+g2a79d-py3.5-linux-x86_64.egg/SimpleITK/SimpleITK.py", line 10996, in Execute
return _SimpleITK.ElastixImageFilter_Execute(self)
RuntimeError: Exception thrown in SimpleITK ElastixImageFilter_Execute: /home/francisr/registration/SimpleElastix/Code/BasicFilters/src/sitkCastImageFilter.cxx:99:
sitk::ERROR: Filter does not support casting from casting vector of 8-bit unsigned integer to 32-bit float
Hi @francisr. You have to cast to a vector of 32-bit float (if that's what you intend to do) or use VectorIndexSelectionCastImageFilter() and choose which component of the vector image you want to extract and cast.
Same problem, I have two images
IF_itk_x4 = sitk.GetImageFromArray(IF_np_x4_norm, sitk.sitkFloat32)
HE_itk_x4 = sitk.GetImageFromArray(HE_np_x4_norm, sitk.sitkFloat32)
and want to do affine registration:
elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(HE_itk_x4)
elastixImageFilter.SetMovingImage(IF_itk_x4)
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap("affine"))
elastixImageFilter.Execute()
and get the error:
RuntimeError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\simpleitk-2.0.0+ggitdir.notfound-py3.8-win-amd64.egg\SimpleITK\SimpleITK.py in Execute(self) 11128 def Execute(self): 11129 """Execute(ElastixImageFilter self) -> Image""" 11130 return _SimpleITK.ElastixImageFilter_Execute(self) 11131 11132
RuntimeError: Exception thrown in SimpleITK ElastixImageFilter_Execute: C:\Users\Lorenz\Documents\libraries\SimpleElastix\Code\BasicFilters\src\sitkCastImageFilter.cxx:101: sitk::ERROR: Filter does not support casting from casting vector of 32-bit float to 32-bit float
I was able to solve this with your suggestion:
selectCastFilter = sitk.VectorIndexSelectionCastImageFilter()
selectCastFilter .SetIndex(0)
selectCastFilter .SetOutputPixelType(sitk.sitkFloat32)
HE_res = selectCastFilter .Execute(HE_itk_x4)
IF_res = selectCastFilter .Execute(IF_itk_x4)