Automate Fiducial Registration

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.

Fiducial Registration module is a CLI module, which can be run from Python as described here: Documentation/Nightly/Developers/Python scripting - Slicer Wiki

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.

1 Like

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

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.

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?

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
1 Like

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.

1 Like

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.

A post was split to a new topic: Automate model to CT registration