How to do batch registration?

Thank you ,yes it’s really somewhat complex for me a newbee… :joy:I’ve solved the batch registration problem in windows:

  1. Write a batch registration script: example
## Run the following command in Python Console.
# execfile("path\to\BatchRegister.py")
def Register(Fixedfilename,Movingfilename,OutVolumefilename,ind):
    Nodename = 'Volume_{:02d}'.format(ind)
    RegistrationPresets_ParameterFilenames = 5
    # Load Volume
    [ success,movingVolumeNode ] = slicer.util.loadVolume(Movingfilename,returnNode=True)
    [ success, fixedVolumeNode] = slicer.util.loadVolume(Fixedfilename,returnNode=True)
    

    from Elastix import ElastixLogic
    logic = ElastixLogic()
    parameterFilenames = logic.getRegistrationPresets()[0][RegistrationPresets_ParameterFilenames]
    outputVolume = slicer.vtkMRMLScalarVolumeNode()
    slicer.mrmlScene.AddNode(outputVolume)
    outputVolume.CreateDefaultDisplayNodes()
    outputVolume.SetName(Nodename)
    logic.registerVolumes(fixedVolumeNode, movingVolumeNode, parameterFilenames = parameterFilenames , outputVolumeNode = outputVolume)

    # Create OutputVolume Node.
    myNode = getNode(Nodename)
    myStorageNode = myNode.CreateDefaultStorageNode()
    myStorageNode.SetFileName(OutVolumefilename)
    myStorageNode.WriteData(myNode)
    slicer.mrmlScene.Clear(0)



def BatchRegister():
    path2subjects = 'path\to\dataset_directory'
    import os
    for ind,dir in enumerate(os.listdir(path2subjects)):
        Fixedfilename = os.path.join(path2subjects,dir,'Fixed.ext')
        print(Fixedfilename)
        Movingfilename = os.path.join(path2subjects,dir,'Moving.ext')
        OutVolumefilename = os.path.join(path2subjects,dir,'OutVolume.ext')
        Register(Fixedfilename, Movingfilename, OutVolumefilename,ind)
BatchRegister()

2.Execute the Python script in the Slicer’s Python command as follow:
>>execfile("path\to\BatchRegister.py")

5 Likes