# Automate Fiducial Registration

**URL:** <https://discourse.slicer.org/t/automate-fiducial-registration/3061>\
**Category:** Development\
**Created:** [June 3, 2018, 10:03pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061 "2018-06-03T22:03:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hikmat](https://avatars.discourse-cdn.com/v4/letter/h/ecccb3/32.png) [@Hikmat](https://discourse.slicer.org/u/Hikmat)\
**Post date:** [June 3, 2018, 10:03pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/1 "2018-06-03T22:03:28Z")

</div>

Operating system: Windows 10  
Slicer version: Slicer 4.8.1

Hi,

I am writing a simulator which requires the registration of CT and MRI images. I am satisfied with Fiducial Registration; however, the steps required to perform this procedure may be intensive to the user (Registration -\> Specialized -\> Fiducial Registration -\> Fixed Landmarks -\> Moving Landmarks -\> Save Transform -\> Apply)

I would like to automate this registration procedure (implement it programmatically) to simplify the U/I steps (I would still require the user to create the markups manually). Is there some code snippet for automating the Fiducial Registration module and setting its respective parameters? I went through the ScriptRepository Documentation but couldn’t find what I was looking for.

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 4, 2018, 2:07pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/2 "2018-06-04T14:07:26Z")

</div>

Fiducial Registration module is a CLI module, which can be run from Python as described here: [Documentation/Nightly/Developers/Python scripting - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#Running_a_CLI_from_Python)

> [@Hikmat](#):
>
> I would like to automate this registration procedure (implement it programmatically) to simplify the U/I steps (I would still require the user to create the markups manually)

Once you’ve figured out a complete processing workflow and you would like to perform it many times or you would like inexperienced users to reproduce the workflow then writing a custom Python scripted module is a good idea. I would strongly recommend to not require users to create any nodes manually. You can save all the nodes that your module is using into a scripted parameter node - see more details [here](https://www.slicer.org/wiki/Documentation/Nightly/Developers/FAQ/Python_Scripting#How_to_save_user.27s_selection_of_parameters_and_nodes_in_the_scene.3F).

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [June 6, 2018, 11:11am UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/3 "2018-06-06T11:11:04Z")

</div>

Did you found the method for automating the Fiducial Registryation with CLI?

---

<div class="post-metadata">

**Author:** ![Hikmat](https://avatars.discourse-cdn.com/v4/letter/h/ecccb3/32.png) [@Hikmat](https://discourse.slicer.org/u/Hikmat)\
**Post date:** [June 6, 2018, 2:12pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/4 "2018-06-06T14:12:23Z")

</div>

Yes, I did. Apologies for not updating the status quo, it’s just that I’m still thinking about how I want to go about this.

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [October 15, 2018, 4:48pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/5 "2018-10-15T16:48:06Z")

</div>

**Related question,**

How to use this module from cmd. It is not clear how to provide the landmarks as input ordered list arguments and it would be nice to add this to the module wiki. I tried:

```
   ~/sw/Slicer-4.8.1/Slicer --launch ~/sw/Slicer-4.8.1/lib/Slicer-4.8/cli-modules/FiducialRegistration --returnparameterfile transform.txt --transformType Rigid --saveTransform --movingLandmarks -42.3584 -32.6622 24.675 -2.39974 -40.2918 -35.3744 -8.60695 -41.5944 --fixedLandmarks -12.753 -180.318 -251.67 26.5668 -143.192 -246.78 -33.6808 -138.784

```

I also tried using [x y z] or [x,y,z] and () in addition to provide the fixed and landmarks as fcsv files but nothing works

What is the correct format for providing the landmarks?

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [October 16, 2018, 4:26pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/6 "2018-10-16T16:26:00Z")

</div>

Here is a python script example:

```
 # create a transform node and add it to the scene
 transformNode = slicer.vtkMRMLLinearTransformNode()
 slicer.mrmlScene.AddNode(transformNode) 

parameters = {}
parameters["saveTransform"] = transformNode.GetID() 
parameters["movingLandmarks"] = movingMarkupNode.GetID() # fiducial points  
parameters["fixedLandmarks"] = fixedMarkupNode.GetID() # fiducial points  
fiduciaReg = slicer.modules.fiducialregistration
slicer.cli.runSync(fiduciaReg, None, parameters) # run the registration
```

---

<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:** [October 16, 2018, 4:34pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/7 "2018-10-16T16:34:04Z")

</div>

> [@brhoom](#):
>
> What is the correct format for providing the landmarks?

You can run a CLI from the GUI and see in application log what command was used. If you enable developer mode in application settings then all input and output files are preserved after running a CLI module, so you can inspect file content, too.

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [October 16, 2018, 4:43pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/8 "2018-10-16T16:43:58Z")

</div>

> see in application log

Cool, this is really useful, in Ubuntu I found it in /tmp/Slicer-username/Slicer\_version\_date\_time.log

Here is an example of the arguments

```
        --returnparameterfile file.params --fixedLandmarks 1.854,-127.381,-260.861 --fixedLandmarks -3.282,-126.126,-261.026 --fixedLandmarks -6.907,-126.92,-261.026 --movingLandmarks -4.91273,5.92777,-58.4992 --movingLandmarks -7.72868,5.14361,-58.4387 --movingLandmarks -11.3224,4.54754,-57.7137 --saveTransform trsform.txt --transformType Rigid

```

so we need to use --fixedLandmarks and --fixedLandmarks multiple times.

---

<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 26, 2020, 3:18pm UTC](https://discourse.slicer.org/t/automate-fiducial-registration/3061/9 "2020-06-26T15:18:24Z")

</div>

A post was split to a new topic: [Automate model to CT registration](https://discourse.slicer.org/t/automate-model-to-ct-registration/12234)
