# How to create a clone Fiducials then transform the original fiducials onto the clone fiducials

**URL:** <https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124>\
**Category:** Support\
**Tags:** markups-fiducials\
**Created:** [November 13, 2019, 6:19am UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124 "2019-11-13T06:19:19Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 13, 2019, 6:19am UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/1 "2019-11-13T06:19:19Z")

</div>

Hi,

Using this code i created 3 markup fiducials,

```
slicer.modules.markups.logic().AddFiducial(random.random()*5.0 ,random.random()*5.0,random.random()*5.0) 

```

I want to create another 3 clone fiducials close to these fiducials( same identical to original fiducials) then I want to transform my original fiducials to the clone fiducials. This is how I’m transforming using a matrix transform. This code only gets 1 markup fiducials after I name that to F, but not the randomized 3 fiducials point.

basically, I want is slicer.util.getNode() will get the fiducial point I created randomly using code slicer.modules.markups.logic().AddFiducial()

```
    F1 = slicer.util.getNode('F')

    transformMatrixNP = np.array(
        [[1, 0, 0, 10],
         [0, 1, 0, 0],
         [0, 0, 1, 0],
         [0, 0, 0, 1]])

    transformMatrixVTK = vtk.vtkMatrix4x4()
    for row in range(4):
        for col in range(4):
            transformMatrixVTK.SetElement(row, col, transformMatrixNP[row, col])

    F1.ApplyTransformMatrix(transformMatrixVTK)
```

---

<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:** [November 14, 2019, 1:49am UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/2 "2019-11-14T01:49:19Z")

</div>

It is not completely clear what you would like to achieve but if you use a recent Slicer Preview version then this example should help you get started:

```python
import numpy as np

pointCoordsNP = np.random.rand(5,3)*30

transformMatrixNP = np.array(
    [[1, 0, 0, 10],
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1]])

originalFidNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
slicer.util.updateMarkupControlPointsFromArray(originalFidNode, pointCoordsNP)

transformedFidNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
slicer.util.updateMarkupControlPointsFromArray(transformedFidNode, pointCoordsNP)
transformedFidNode.ApplyTransformMatrix(slicer.util.vtkMatrixFromArray(transformMatrixNP))
transformedControlPointsNP = slicer.util.arrayFromMarkupsControlPoints(transformedFidNode)

print(pointCoordsNP)
print(transformedControlPointsNP)

```

---

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 14, 2019, 12:30pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/3 "2019-11-14T12:30:04Z")

</div>

basically this is what I want to do,

 ![IMG_20191114_202130](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/2/a24576bbe42899ed52a38ebbf0c326b30d6f4593.jpeg)

---

<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:** [November 14, 2019, 2:41pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/4 "2019-11-14T14:41:25Z")

</div>

The example script does this or something very similar. If you want to compute the transform automatically then you can use Fiducial registration wizard module in SlicerIGT extension.

---

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 14, 2019, 3:00pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/5 "2019-11-14T15:00:17Z")

</div>

Can you help me to understand it very easily , I want to perform this manually?

---

<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:** [November 14, 2019, 3:11pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/6 "2019-11-14T15:11:25Z")

</div>

By manually do you mean using GUI or Python scripting?

---

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 14, 2019, 3:17pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/7 "2019-11-14T15:17:04Z")

</div>

Most probably python scripting. I’m adding python codes in the dicom python file .  
Right now i know how to create randomly Fiducials and Matrix transformation of that fiducials.

So now , i will do registration of a fiducials onto another fiducials.  
so , lets say ,i created 2 fiducial side by side and now i want 1 of the fiducial to be transformed onto another fiducial. can u please explain me how should i approach this situation?

---

<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:** [November 14, 2019, 3:23pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/8 "2019-11-14T15:23:34Z")

</div>

This sounds like basic landmark registration. See [U-12 SlicerIGT tutorial](http://www.slicerigt.org/wp/user-tutorial/) for step-by-step instructions.

---

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 14, 2019, 3:34pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/9 "2019-11-14T15:34:48Z")

</div>

Thanks for your reply but i was looking for how to do that by coding.

---

<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:** [November 14, 2019, 3:44pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/10 "2019-11-14T15:44:35Z")

</div>

To perform landmark registration from Python, add a [vtkMRMLFiducialRegistrationWizardNode](https://github.com/SlicerIGT/SlicerIGT/blob/master/FiducialRegistrationWizard/MRML/vtkMRMLFiducialRegistrationWizardNode.h) node to the scene, set input markup fiducial nodes (`SetAndObserveFromFiducialListNodeId` and ` SetAndObserveToFiducialListNodeId`), output transform node (`SetOutputTransformNodeId`), and optionally other registration parameters, then call `SetUpdateModeToAuto()` to enable computation of the output transform automatically. You can verify if you have set all parameters correctly in the Fiducial registration wizard module GUI.

---

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 14, 2019, 3:56pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/11 "2019-11-14T15:56:15Z")

</div>

thank you sir , another thing how to get transform between nodes?

---

<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:** [November 14, 2019, 5:37pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/12 "2019-11-14T17:37:06Z")

</div>

You can get transformation matrix between two nodes by calling [slicer.vtkMRMLTransformNode.GetMatrixTransformBetweenNodes](https://apidocs.slicer.org/master/classvtkMRMLTransformNode.html#acbab274893b3d11cac30c4ee8a036f96) method.

---

<div class="post-metadata">

**Author:** ![ihsanas](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@ihsanas](https://discourse.slicer.org/u/ihsanas)\
**Post date:** [November 14, 2019, 7:28pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/13 "2019-11-14T19:28:29Z")

</div>

sir , after a create a node using this code slicer.modules.markups.logic().AddFiducial(4.0, 7.0, 10.0) , how can i get this node or call this node to use it again?

---

<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:** [November 14, 2019, 7:42pm UTC](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/14 "2019-11-14T19:42:25Z")

</div>

I’ve described [above](https://discourse.slicer.org/t/how-to-create-a-clone-fiducials-then-transform-the-original-fiducials-onto-the-clone-fiducials/9124/10) what exact method you need to call. Transform is computed (and recomputed if any of the inputs change) automatically if UpdateMode is set to Auto.
