# FIducial Registration Wizard through Python Interactor

**URL:** <https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641>\
**Category:** Support\
**Created:** [September 23, 2020, 4:44am UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641 "2020-09-23T04:44:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Purva\_Suryawanshi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/purva_suryawanshi/32/8039_2.png) [@Purva\_Suryawanshi](https://discourse.slicer.org/u/Purva_Suryawanshi)\
**Post date:** [September 23, 2020, 4:44am UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/1 "2020-09-23T04:44:06Z")

</div>

Operating system:Windows 10  
Slicer version:4.11.0  
Expected behavior:I want to align a DICOM volume and an Image using 3 points (fiducial markers) through python. Is there a way I can assign the fiducial markers using python?  
Actual behavior:

---

<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:** [September 23, 2020, 2:04pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/2 "2020-09-23T14:04:56Z")

</div>

Yes, of course. All features of Slicer are available from Python. You can create markups fiducial nodes and add points using Python, create a vtkMRMLFiducialRegistrationWizardNode, set its inputs, and use fiducial registration wizard module logic to compute the results (or enable auto-update in your vtkMRMLFiducialRegistrationWizardNode to automatically update output transform from the input points).

You will find [this tutorial](https://www.slicer.org/wiki/Documentation/Nightly/Training#PerkLab.27s_Slicer_bootcamp_training_materials) useful and you can find lots of examples in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository).

---

<div class="post-metadata">

**Author:** ![Andinet\_Enquobahrie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andinet_enquobahrie/32/75_2.png) [@Andinet\_Enquobahrie](https://discourse.slicer.org/u/Andinet_Enquobahrie)\
**Post date:** [October 7, 2020, 8:07pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/3 "2020-10-07T20:07:31Z")

</div>

Hi @Purva_Suryawanshi

Just to give you a short example how you can do this ( to add to @lassoan response )

```
 # Create markups node to store "From" fiducials
 fromMarkupsNodeID = slicer.modules.markups.logic().AddNewFiducialNode()
 fromMarkupsNode = getNode(fromMarkupsNodeID)
 fromMarkupsNode.SetName(“From”)

 # Create markup node to store "To" fiducials
 toMarkupsNodeID = slicer.modules.markups.logic().AddNewFiducialNode()
 toMarkupsNode = getNode(toMarkupsNodeID)
 toMarkupsNode.SetName(“To”)

# Add fiducials to the markup list as follows manually
fromPoint1= [1.0, 2.0, 3.0]
fromPoint2= [2.0, 4.0, 6.0]
fromPoint3= [3.0, 6.0, 9.0]
fromMarkupsNode.AddFiducial(fromPoint1[0], fromPoint1[1], fromPoint1[2] )
fromMarkupsNode.AddFiducial(fromPoint2[0], fromPoint2[1], fromPoint2[2] )
fromMarkupsNode.AddFiducial(fromPoint3[0], fromPoint3[1], fromPoint3[2] )

toPoint1= [4.0, 5.0, 6.0]
toPoint2= [8.0, 10.0, 12.0]
toPoint3= [12.0, 15.0, 18.0]
toMarkupsNode.AddFiducial(toPoint1[0], toPoint1[1], toPoint1[2] )
toMarkupsNode.AddFiducial(toPoint2[0], toPoint2[1], toPoint2[2] )
toMarkupsNode.AddFiducial(toPoint3[0], toPoint3[1], toPoint3[2] )

# Create transform node to hold the computed registration result
transformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLinearTransformNode")
transformNode.SetName("Registration Transform")

#Create your fiducial wizard node and set the input parameters
myfiducialRegistrationWizardNode = 
    slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLFiducialRegistrationWizardNode”)

myfiducialRegistrationWizardNode.SetAndObserveFromFiducialListNodeId(fromMarkupsNodeID)
myfiducialRegistrationWizardNode.SetAndObserveToFiducialListNodeId(toMarkupsNodeID)
myfiducialRegistrationWizardNode.SetOutputTransformNodeId(transformNode.GetID())
myfiducialRegistrationWizardNode.SetRegistrationModeToSimilarity()

```

Hope this helps  
Andinet

---

<div class="post-metadata">

**Author:** ![Vincebisca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincebisca/32/10722_2.png) [@Vincebisca](https://discourse.slicer.org/u/Vincebisca)\
**Post date:** [May 19, 2021, 9:10am UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/4 "2021-05-19T09:10:36Z")

</div>

Hello,

I want to ask a question on the code you wrote there: when I try to use it, slicer says that vtkMRMLFiducialRegistrationWizardNode doesn’t exist… I don’t really understand what I’m missing since I am not used to coding, but I tried various things like adding slicer.modules etc… But nothing seems to work. Do you have a clue on what’s going on?

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:** [May 19, 2021, 12:32pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/5 "2021-05-19T12:32:51Z")

</div>

Have you installed SlicerIGT extension?

---

<div class="post-metadata">

**Author:** ![Vincebisca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincebisca/32/10722_2.png) [@Vincebisca](https://discourse.slicer.org/u/Vincebisca)\
**Post date:** [May 19, 2021, 12:41pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/6 "2021-05-19T12:41:24Z")

</div>

No indeed I didn’t, but then Fiducial Registration Wizard is not the same as the Fiducial Registration module that there is on the classic version of Slicer? Because that is the one I wish to use.

Searching a bit, I found that the following code works to create a transform from 2 lists of fiducials :

```
transformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLinearTransformNode")
transformNode.SetName("Registration Transform")
parameters = {}
parameters["saveTransform"] = transformNode.GetID()
parameters["movingLandmarks"] = self.VariableMarkupsNode.GetID() # fiducial points
parameters["fixedLandmarks"] = self.FixedMarkupsNode.GetID() # fiducial points
fiduciaReg = slicer.modules.fiducialregistration
slicer.cli.runSync(fiduciaReg, None, parameters) # run the registration

```

Precision : the code is not mine, I found it [here](https://discourse.slicer.org/t/automate-fiducial-registration/3061/5).

I have now to find how to apply the transform to the volume I wish to move

---

<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:** [May 19, 2021, 12:47pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/7 "2021-05-19T12:47:53Z")

</div>

> [@Vincebisca](#):
>
> slicer says that vtkMRMLFiducialRegistrationWizardNode doesn’t exist…

You got this error because you haven’t installed SlicerIGT extension, therefore there is no such node type as “vtkMRMLFiducialRegistrationWizardNode”.

> [@Vincebisca](#):
>
> I found that the following code works to create a transform from 2 lists of fiducials

Yes, this code snippet looks good.

> [@Vincebisca](#):
>
> I have now to find how to apply the transform to the volume I wish to move

You can find example scripts for all commonly needed tasks in the [Script Repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#apply-a-transform-to-a-transformable-node).

---

<div class="post-metadata">

**Author:** ![Vincebisca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincebisca/32/10722_2.png) [@Vincebisca](https://discourse.slicer.org/u/Vincebisca)\
**Post date:** [May 19, 2021, 12:54pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/8 "2021-05-19T12:54:35Z")

</div>

I believe that I found out for the transform part in the script repository yes, I had a little struggle to select the transformed node from a ComboBox but it’s solved.

I have a question : using the fiducial registration as I did, is there a way to change the registration type? Like in the Fiducial Registration module there is the choice between “translation” “rigid” and “similarity”. Can I access those with my code?

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:** [May 19, 2021, 3:26pm UTC](https://discourse.slicer.org/t/fiducial-registration-wizard-through-python-interactor/13641/9 "2021-05-19T15:26:57Z")

</div>

You can get the list of CLI parameter nodes as shown [here](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html#get-list-of-parameter-names).
