python ThinPlateSpline and point set

Hello community,
I don’t manage to get the proper point set to work with the tps transform. Here is a minimal example:

PixelType = itk.D
Dimension = 2

point_set = itk.PointSet[PixelType, Dimension].New()
ref_point_set = itk.PointSet[PixelType, Dimension].New()

# fill the point set ...

tps = itk.ThinPlateSplineKernelTransform.New()
tps.SetSourceLandmarks(point_set)  # this does not work
tps.SetTargetLandmarks(ref_point_set)
tps.ComputeWMatrix()

In C++ I use directly the PointSetType in the ThinPlateSplineKernelTransform. Any idea how to get the right combination of point type and tps in python ?

Thanks a lot in advance !

It may not be the most optimal solution, but I got it working, so I’m sharing the code as it could be useful for others:

PixelType = itk.D
Dimension = 2

point_set = itk.PointSet[PixelType, Dimension].New()
ref_point_set = itk.PointSet[PixelType, Dimension].New()

# fill the point set ...

tps = itk.ThinPlateSplineKernelTransform.New()
pts_source = tps.GetModifiableSourceLandmarks()
pts_target = tps.GetModifiableTargetLandmarks()
pts_source_d = pts_source.GetPoints()
pts_target_d = pts_target.GetPoints()
for i in range(point_set.GetNumberOfPoints()):
    pts_target_d.InsertElement(i, point_set.GetPoint(i))
    pts_source_d.InsertElement(i, ref_point_set.GetPoint(i))

tps.ComputeWMatrix()
1 Like