无法编写图像SimpleElastix(Python)

时间:2017-08-22 20:42:48

标签: python c++ itk simpleitk

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

感谢。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

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

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

修改:您可以尝试使用其他文件扩展名:result.pngresult.tifresult.nrrdresult.mha等。