# Apply transform to a given fiducial in Python script

**URL:** https://discourse.slicer.org/t/apply-transform-to-a-given-fiducial-in-python-script/7239
**Category:** Development
**Created:** [June 19, 2019, 1:51pm UTC](https://discourse.slicer.org/t/apply-transform-to-a-given-fiducial-in-python-script/7239 "2019-06-19T13:51:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Eloise](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eloise/32/3948_2.png) [@Eloise](https://discourse.slicer.org/u/Eloise)
#### Post date: [June 19, 2019, 1:51pm UTC](https://discourse.slicer.org/t/apply-transform-to-a-given-fiducial-in-python-script/7239/1 "2019-06-19T13:51:10Z")

</div>

Hi all,

I have a vtkMRMLMarkupsFiducialNode that contains multiple fiducials corresponding to distinct labels and I would like to apply a specific vtkMRMLTransform to each given fiducial depending on its label.  
I have found how to apply a given transform to the vtkMRMLMarkupsFiducialNode using  
FiducialsNode.SetAndObserveTransformNodeID(localTransformNode.GetID()) but I don’t know how to do it for each fiducial independently.

Can someone point me in the right direction? Thanks!

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [June 19, 2019, 2:07pm UTC](https://discourse.slicer.org/t/apply-transform-to-a-given-fiducial-in-python-script/7239/2 "2019-06-19T14:07:44Z")

</div>

If you need to apply a different transform to each point then you need to iterate through the points, get the point position, compute transformed position, and set the modified value.

If you only have linear transforms then you can use [GetMatrixTransformToWorld](https://apidocs.slicer.org/v4.8/classvtkMRMLTransformNode.html#a5d2d93382aa7da7ec3d9a27987305bce) method to get the transformation matrix and use its [MultiplyPoint](https://vtk.org/doc/nightly/html/classvtkMatrix4x4.html#a63b1e05c7e106bbee9cc606c27d6260d) method to get the transformed coordinates (input and output are homogeneous coordinates: `[x, y, z, 1.0]`)

---

<div class="post-metadata">

### Author: ![Eloise](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eloise/32/3948_2.png) [@Eloise](https://discourse.slicer.org/u/Eloise)
#### Post date: [July 24, 2019, 8:19am UTC](https://discourse.slicer.org/t/apply-transform-to-a-given-fiducial-in-python-script/7239/3 "2019-07-24T08:19:49Z")

</div>

Hi,

I’m re-opening the question. The solution works perfectly when I only have linear transforms, then, what can I do when vtkMRMLTransform is a composite of Bspline and linear transforms, since I cannot get the transformation matrix (GetMatrixTransformToWorld returns 0) ?  
Thanks for your help!

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 25, 2019, 3:39am UTC](https://discourse.slicer.org/t/apply-transform-to-a-given-fiducial-in-python-script/7239/4 "2019-07-25T03:39:13Z")

</div>

For general (non-linear, potentially composite) transforms you can get it using `slicer.vtkMRMLTransformNode.GetTransformBetweenNodes` and use its `TransformPoint` method to transform point coordinates. See complete example in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_volume_voxel_coordinates_from_markup_fiducial_RAS_coordinates).
