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

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)

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:

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)

basically this is what I want to do, IMG_20191114_202130

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.

1 Like

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

By manually do you mean using GUI or Python scripting?

1 Like

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?

This sounds like basic landmark registration. See U-12 SlicerIGT tutorial for step-by-step instructions.

1 Like

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

To perform landmark registration from Python, add a vtkMRMLFiducialRegistrationWizardNode 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.

1 Like

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

You can get transformation matrix between two nodes by calling slicer.vtkMRMLTransformNode.GetMatrixTransformBetweenNodes method.

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?

I’ve described above 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.