SimpleElastix icon indicating copy to clipboard operation
SimpleElastix copied to clipboard

Filter does not support casting from casting vector of 8-bit unsigned integer to 32-bit float

Open francisr opened this issue 6 years ago • 2 comments

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

francisr avatar May 16 '19 13:05 francisr

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.

kaspermarstal avatar May 21 '19 07:05 kaspermarstal

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) in 3 elastixImageFilter.SetMovingImage(IF_itk_x4) 4 elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap("affine")) ----> 5 elastixImageFilter.Execute()

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)

JLrumberger avatar May 31 '21 12:05 JLrumberger