python interactor - General Registration (BRAINS) module

Dear all,
I’m working with a large amount of CT scans and I need to apply rigid registration between series acquired at different time points. Using simpleITK I’m still not able to reach results good enough in a reasonable time compared to those obtained through the General Registration (BRAINS) module. Therefore I’m trying to apply it through python interactive module. Is the approach reported below correct? How can I save the obtained transformation so to apply it in a second moment so to avoid saving the transformed image?

scene = slicer.mrmlScene
slicer.util.selectModule('BRAINSFit')
brainsFit = slicer.modules.brainsfit

t0 = slicer.util.loadVolume('fixed.mha')
t1 = slicer.util.loadVolume('moving.mha')

shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)

parametersRigid = {}
parametersRigid["fixedVolume"] = t0.GetID()
parametersRigid["movingVolume"] = t1.GetID()

linearTransform = slicer.vtkMRMLLinearTransformNode()
linearTransform.SetName('t12t0Rigid')
slicer.mrmlScene.AddNode( linearTransform )

parametersRigid["linearTransform"] = linearTransform.GetID()
parametersRigid["useRigid"] = True
parametersRigid["samplingPercentage"] = 0.0002

cliBrainsFitRigidNode = None
cliBrainsFitRigidNode = slicer.cli.run(brainsFit, None, parametersRigid)
waitCount = 0
delayMs =700
while cliBrainsFitRigidNode.GetStatusString() != 'Completed' and waitCount < 200:
         delayDisplay( "Register Day 2 CT to Day 1 CT using rigid registration... %d" % waitCount, delayMs )
         waitCount += 1
delayDisplay("Register Day 2 CT to Day 1 CT using rigid registration finished",delayMs)

Hi

Your code seems to work fine. Are you getting any errors?

If the script is “skipping” the registration, you might try

cliBrainsFitRigidNode = slicer.cli.runSync(brainsFit, None, parametersRigid)

instead of

For saving the transformation you can use

saveNode(linearTransform, PATH_TO_SAVE_TRANSFORM)

Caio