0

我正在尝试将以下示例作为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

谢谢。

4

2 回答 2

2

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

于 2017-08-22T20:54:23.303 回答
1

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

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

编辑:您可以尝试其他文件扩展名:result.png, result.tif,result.nrrdresult.mha

于 2017-08-22T20:54:42.757 回答