Elastix in custom module

Hello,

I want to implement BSpline registration in a custom module in a seamless way for the user. For the registration I want to use Elastix with the “Generic (all)” preset.

I imported Elastix logic and used ElastixLogic.registerVolumes. I linked it to a Push Button to trigger the registration. My current code is :

def onRegistrationPushed(self):

FixedVolume = self.ui.SeqFixeSelector.currentNode()
MovingVolume = self.ui.SeqVariableSelector.currentNode()
parameters = "Parameters_BSpline.txt"
Transform = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLBSplineTransformNode")
volumesLogic = slicer.modules.volumes.logic()
OutputVolume = volumesLogic.CloneVolume(slicer.mrmlScene, MovingVolume, MovingVolume.GetName() + '_Registered' )

ElastixLogic.registerVolumes(self,FixedVolume, MovingVolume,parameters,OutputVolume, Transform)

However, when I tried to run it in 3DSlicer with 2 image sequences, it gave the error :

AttributeError: ‘GemSegmentWidget’ object has no attribute ‘createTempDirectory’

GemSegment is my module’s name. Digging a bit I saw that createTempDirectory is a function from Elastix.py, but then I don’t understand why it doesn’t search for it there. I tried to integrate createTempDirectory to my module’s .py file but it just moved the problem upwards, asking for the getTempDirectoryBase function.

If someone can help me understand how to properly use Elastix in my module I would be very glad ! Thank you !

Hi, you need to create an instance i.e. ElastixLogic() rather than ElastixLogic

so

elastixLogic = ElastixLogic()
elastixLogic.registerVolumes(FixedVolume, MovingVolume,parameters,OutputVolume, Transform)

See: SlicerElastix/Elastix.py at 3e9ef490ee6a6f901daa3280af112950f6af13ec · lassoan/SlicerElastix · GitHub

Hi ! Sorry I forgot to reply :sweat_smile:
You were indeed right ! I bumped into a few other issues but I managed to solve it and it work as intended now ! Thank you very much !