SimpleITK Transform.TransformPoint() does not accept variables by reference?

Hello,

I’m trying to apply a Displacement Field Transform to a point using the Transform.TransformPoint(). I’ve been following the example on this webpage: 21_Transforms_and_Resampling

I currently have a M \cdot 2 numpy array of points that I would like to transform using the TransformPoint() function so I pass in one point at a time. However, I receive the following error when attempting to do so:

TypeError: in method 'Transform_TransformPoint', argument 2 of type 'std::vector< double,std::allocator< double > > const &'

I’ve run the following tests:
T is of type SimpleITK.DisplacementFieldTransform(). It has a dimension of 2.

Works

p1 = (100,100)
p2 = [100,100]
T.TransformPoint((100,100)) = (121.52352626788556, 121.38996079802627)
T.TransformPoint([100,100]) = ...
T.TransformPoint([100.0,100.0]) = ...

Does Not Work

x = 100
y = 100
p1 = (100,100) # Type tuple
p2 = [100,100] # Type list
T.TransformPoint((x, y)) = TypeError
T.TransformPoint([x,y]) = TypeError
T.TransformPoint(p1) = TypeError
T.TransformPoint(p2) = TypeError

I’m not really sure how I can fix this from the Python end but I am open to suggestions.

I’m currently running this on Windows 10 in an Anaconda environment with SimpleITK installed.

Hello @bbikdash,

The solution is to use numpy’s tolist method and a list comprehension:

import SimpleITK as sitk
import numpy as np

dim = 2
num_points = 5

T = sitk.TranslationTransform(dim)
T.SetOffset([3]*dim)
points = np.random.random((num_points,dim)).tolist()
transformed_points = [T.TransformPoint(p) for p in points]

print(points)
print(transformed_points)
2 Likes