# Elastix in custom module

**URL:** <https://discourse.slicer.org/t/elastix-in-custom-module/24813>\
**Category:** Development\
**Created:** [August 17, 2022, 5:48pm UTC](https://discourse.slicer.org/t/elastix-in-custom-module/24813 "2022-08-17T17:48:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincebisca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincebisca/32/10722_2.png) [@Vincebisca](https://discourse.slicer.org/u/Vincebisca)\
**Post date:** [August 17, 2022, 5:48pm UTC](https://discourse.slicer.org/t/elastix-in-custom-module/24813/1 "2022-08-17T17:48:16Z")

</div>

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):

```auto
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 !

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [August 18, 2022, 3:44pm UTC](https://discourse.slicer.org/t/elastix-in-custom-module/24813/2 "2022-08-18T15:44:24Z")

</div>

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

so

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

```

See: [SlicerElastix/Elastix.py at 3e9ef490ee6a6f901daa3280af112950f6af13ec · lassoan/SlicerElastix · GitHub](https://github.com/lassoan/SlicerElastix/blob/3e9ef490ee6a6f901daa3280af112950f6af13ec/Elastix/Elastix.py#L939)

---

<div class="post-metadata">

**Author:** ![Vincebisca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincebisca/32/10722_2.png) [@Vincebisca](https://discourse.slicer.org/u/Vincebisca)\
**Post date:** [August 26, 2022, 3:20pm UTC](https://discourse.slicer.org/t/elastix-in-custom-module/24813/3 "2022-08-26T15:20:52Z")

</div>

Hi ! Sorry I forgot to reply 😅  
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 !
