0

I'm trying to run the following example as part of the SimpleElastix library:

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())

When I try to run the above code, I get the following error (I'm showing part of the output):

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)

How can I solve this issue?

EDIT: As per @Dženan's answer, I got the following:

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

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • This question now appears to be a duplicate of https://stackoverflow.com/questions/45570341/python-write-a-three-dimensional-image-from-3d-array/45571309?noredirect=1#comment78102006_45571309 – blowekamp Aug 28 '17 at 19:13

2 Answers2

2

As listed in the c++ prototypes, you are missing the second argument, the filename.

blowekamp
  • 1,401
  • 7
  • 7
2

You are missing a file name. Try this:

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

Edit: you can try other file extensions: result.png, result.tif, result.nrrd, result.mha etc.

Dženan
  • 3,329
  • 3
  • 31
  • 44