# python ThinPlateSpline and point set

**URL:** https://discourse.itk.org/t/python-thinplatespline-and-point-set/2185
**Category:** Beginner Questions
**Created:** [August 21, 2019, 2:26pm UTC](https://discourse.itk.org/t/python-thinplatespline-and-point-set/2185 "2019-08-21T14:26:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![asertyuio](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/e68b1a/32.png) [@asertyuio](https://discourse.itk.org/u/asertyuio)
#### Post date: [August 21, 2019, 2:26pm UTC](https://discourse.itk.org/t/python-thinplatespline-and-point-set/2185/1 "2019-08-21T14:26:35Z")

</div>

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

```auto
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 !

---

<div class="post-metadata">

### Author: ![asertyuio](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/e68b1a/32.png) [@asertyuio](https://discourse.itk.org/u/asertyuio)
#### Post date: [August 21, 2019, 4:00pm UTC](https://discourse.itk.org/t/python-thinplatespline-and-point-set/2185/2 "2019-08-21T16:00:22Z")

</div>

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:

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

```
