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:
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 useful and you can find lots of examples in the script repository.
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
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 !
Have you installed SlicerIGT extension?
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.
I have now to find how to apply the transform to the volume I wish to move
You got this error because you haven’t installed SlicerIGT extension, therefore there is no such node type as “vtkMRMLFiducialRegistrationWizardNode”.
Yes, this code snippet looks good.
You can find example scripts for all commonly needed tasks in the Script Repository.
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
You can get the list of CLI parameter nodes as shown here.