simeks/deform

pydeform error: unable to cast Python instance to C++ instance

Closed this issue · 2 comments

I've got the following error regardless of use_gpu status.

>>> settings = {
...     'pyramid_levels':6,
...     'pyramid_stop_level': 1,
...     'block_size': [64,64,64],
...     'block_energy_epsilon':1e-7,
...     'max_iteration_count':-1,
...     'constraints_weight':1000.0,
...     'image_slots': 
...     [
...         {
...             'resampler': 'gaussian',
...             'normalize': True,
...             'cost_function':
...             [
...                 {
...                     'function':'ncc',
...                     'weight':1.0,
...                     'radius':7
...                 }
...             ]
...         }
...     ]
... }
>>> df = pydeform.register(
...     fixed,
...     moving,
...     settings=settings,
...     log=log_file,
...     log_level=pydeform.LogLevel.Verbose,
...     num_threads=48,
...     use_gpu=True
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Unable to cast Python instance of type <class 'str'> to C++ type 'std::vector<stk::Volume, std::allocator<stk::Volume> >'

What are fixed and moving in this case? Seems like you're trying to pass strings rather than images. To load the images first you'll have to do something like:

fixed = pydeform.read_volume('fixed.vtk')
moving = pydeform.read_volume('moving.vtk')

If you prefer to use SimpleITK for reading images you could use the SimpleITK API:

import pydeform.sitk_api as pydeform

fixed = sitk.ReadImage('fixed.vtk')
moving = sitk.ReadImage('moving.vtk')

pydeform.register(fixed, moving)

You have examples of both approaches here: https://github.com/simeks/deform/tree/development/examples

Now worked. Thank you.