# How to do batch registration?

**URL:** <https://discourse.slicer.org/t/how-to-do-batch-registration/9633>\
**Category:** Support\
**Tags:** registration\
**Created:** [December 28, 2019, 7:47am UTC](https://discourse.slicer.org/t/how-to-do-batch-registration/9633 "2019-12-28T07:47:50Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Scorbinwen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/scorbinwen/32/2154_2.png) [@Scorbinwen](https://discourse.slicer.org/u/Scorbinwen)\
**Post date:** [December 31, 2019, 6:09am UTC](https://discourse.slicer.org/t/how-to-do-batch-registration/9633/7 "2019-12-31T06:09:05Z")

</div>

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

1. Write a batch registration script: example

```auto
## 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")`

---

_[View the full topic](https://discourse.slicer.org/t/how-to-do-batch-registration/9633)._
