无法写入图像 SimpleElastix (Python)

Not able to write image SimpleElastix (Python)

我正在尝试 运行 以下示例作为 SimpleElastix 库的一部分:

import SimpleITK as sitk

elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(sitk.ReadImage('1.jpg', sitk.sitkFloat32))
elastixImageFilter.SetMovingImage(sitk.ReadImage('2.jpg', sitk.sitkFloat32))
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap('rigid'))
elastixImageFilter.Execute()
sitk.WriteImage(elastixImageFilter.GetResultImage())

当我尝试 运行 上述代码时,出现以下错误(我显示了部分输出):

Traceback (most recent call last):
  File "rigid_transform.py", line 8, in <module>
    sitk.WriteImage(elastixImageFilter.GetResultImage())
  File "/usr/local/lib/python2.7/dist-packages/SimpleElastix-1.0.1rc1.dev331+gd756f-py2.7-linux-x86_64.egg/SimpleITK/SimpleITK.py", line 8015, in WriteImage
    return _SimpleITK.WriteImage(*args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'WriteImage'.
  Possible C/C++ prototypes are:
    itk::simple::WriteImage(itk::simple::Image const &,std::string const &,bool)
    itk::simple::WriteImage(itk::simple::Image const &,std::vector< std::string,std::allocator< std::string > > const &,bool)

我该如何解决这个问题?

编辑:根据@Dženan 的回答,我得到以下信息:

Traceback (most recent call last):
  File "rigid_transform.py", line 8, in <module>
    sitk.WriteImage(elastixImageFilter.GetResultImage(), 'result.jpg')
  File "/usr/local/lib/python2.7/dist-packages/SimpleElastix-1.0.1rc1.dev331+gd756f-py2.7-linux-x86_64.egg/SimpleITK/SimpleITK.py", line 8015, in WriteImage
    return _SimpleITK.WriteImage(*args)
RuntimeError: Exception thrown in SimpleITK WriteImage: /home/me/Desktop/SimpleElastix/build/ITK/Modules/IO/JPEG/src/itkJPEGImageIO.cxx:454:
itk::ERROR: JPEGImageIO(0x1a5daa0): JPEG supports unsigned char/int only

谢谢。

如 c++ 原型中所列,您缺少第二个参数,即文件名。

您缺少文件名。试试这个:

sitk.WriteImage(elastixImageFilter.GetResultImage(), 'result.jpg')

编辑:您可以尝试其他文件扩展名:result.pngresult.tifresult.nrrdresult.mha