Elastix registration-Jupyter

Operating system: Windows 10
Slicer version: 4.11

Elastix registration is not working with the ‘generic rigid’ parameter file. can anyone help me to solve this issue? Actually, I wants to perform the wrist registration.

Current time: Tue Aug 24 22:54:02 2021.
Reading the elastix parameters from file …

ERROR: when reading the parameter file:

itk::ExceptionObject (000000C375D1F210)
Location: “unknown”
File: D:\D\S\S-1-E-b\SlicerElastix-build\elastix\Common\ParameterFileParser\itkParameterFileParser.cxx
Line: 116
Description: itk::ERROR: itk::ERROR: ParameterFileParser(00000257A0F2A430): ERROR: the file E:\slicer\Slicer 4.11.20210226\NA-MIC\Extensions-29738\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Resources\RegistrationParameters\g does not exist.

ERROR: Something went wrong during initialization of the configuration object.
The configuration object has not been initialized.
Errors occurred!

It seems that the parameter file got corrupted. Reinstalling the extension should solve the problem.

I reinstall the extension. Still, the same error occurs.
my code is as follows

RegistrationPresets_ParameterFilenames = 2
parameterFilenames = logic.getRegistrationPresets()[24][RegistrationPresets_ParameterFilenames]
outputVolume = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLScalarVolumeNode')
logic.registerVolumes(fixedVolumeNode= fixedVolumeNode,movingVolumeNode=movingVolumeNode, parameterFilenames = parameterFilenames , outputVolumeNode = outputVolume ,outputTransformNode =outtrans, fixedVolumeMaskNode = dialatedmasklabelmapVolumeNode)

When using the following combination it works. but not registering properly.

RegistrationPresets_ParameterFilenames = 5
parameterFilenames = logic.getRegistrationPresets()[1][RegistrationPresets_ParameterFilenames]

OK, so it seems that the previous problem was solved.

The problems that you have now is due to modifying a built-in constant. Elastix.RegistrationPresets_ParameterFilenames constant is set to 5 and must be kept that way. This is the index of the parameter filenames in the preset list.

This code works perfectly for me:

import Elastix
import SampleData

fixedVolume =  SampleData.downloadSample('MRBrainTumor1')
movingVolume =  SampleData.downloadSample('MRBrainTumor2')
outputVolume = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLScalarVolumeNode')
outputTransform = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTransformNode')
presetIndex = 0

elastixLogic = Elastix.ElastixLogic()
parameterFilenames = elastixLogic.getRegistrationPresets()[presetIndex][Elastix.RegistrationPresets_ParameterFilenames]
    fixedVolume, movingVolume,
    outputVolumeNode = outputVolume,
    parameterFilenames = parameterFilenames,
    outputTransformNode = outputTransform,
    forceDisplacementFieldOutputTransform = True)

You can change the presetIndex = 2, it might give a tiny bit better result, but it also take much longer. In general, I’ve found that the two “generic” presets work very well, but the other presets are hit and miss. They are taken from the Elastix parameter database, so they should work for the specific use cases they developed for, but you may need to experiment with them a bit and tune parameters to work well for your registration tasks.

Also note that Elastix->ITK transformation file conversion is not robust (BSpline output transform is not always correct · Issue #33 · lassoan/SlicerElastix · GitHub), but the resampled output volume and grid transform output are always correct.

ANTs registration extension has been recently added to Slicer. It works very well, too (default presets should work without parameter tuning). You may give it a try.

This works for me. Thank you for that. But in some cases the accuracy is questionable. Is there any other way to perform rigid registration.


I got the results somewhat like this

Does the output image (resampled moving image) aligns well with the fixed image?
If yes, then the misalignment is probably due to the Elastix transform reading bug that I mentioned above (that you can solve by forcing grid transform output).

It gives good outputs only the displacement of the moving image is small. When it comes to large deformation it is not working properly.
I was thinking to perform registration again and again until it gives a good result. So Is there any way to register with an initial transform?