# python code for DiffeomorphicDemonsRegistration in SimpleITK

**URL:** https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937
**Category:** Beginner Questions
**Tags:** simpleitk
**Created:** [June 2, 2019, 7:58am UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937 "2019-06-02T07:58:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)
#### Post date: [June 2, 2019, 7:58am UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/1 "2019-06-02T07:58:50Z")

</div>

I used a few methods for registration. Simple ITK in python looks very easy than using c++ for me.  
Is there any python code available for DiffeomorphicDemonsRegistration?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [June 2, 2019, 5:13pm UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/2 "2019-06-02T17:13:08Z")

</div>

Hello @EE18D504_SINDHURA_C,

Yes,the class for that is [DiffeomorphicDemonsRegistrationFilter](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1DiffeomorphicDemonsRegistrationFilter.html). [This Jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/66_Registration_Demons.ipynb) illustrates various classes from the Demons registration family and their usage in a multi-resolution framework.

---

<div class="post-metadata">

### Author: ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)
#### Post date: [June 4, 2019, 10:27am UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/3 "2019-06-04T10:27:26Z")

</div>

Hi @zivy,  
I have gone throgh the code given here  
I wonder how to use it with my 3D CT brain images?  
I have only two CT images . I dont have any points data.  
how to proceed with only with my two images?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [June 4, 2019, 1:26pm UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/4 "2019-06-04T13:26:39Z")

</div>

Hello @EE18D504_SINDHURA_C,

You do not need point data, that is only used for evaluation purposes.

Please take a look at the “Register and transfer the segmentation.” section of the notebook which registers 2D MRI images. You can readily modify this code for your task. You will need to modify `Euler2DTransform()` to `Euler3DTransform()` in the initializer and possibly tweak the parameters (Demons algorithm and pyramid) to work for your application.

If you are struggling with the code, you might consider using [3D Slicer](https://www.slicer.org/) which has a GUI based registration module.

---

<div class="post-metadata">

### Author: ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)
#### Post date: [June 5, 2019, 6:21am UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/5 "2019-06-05T06:21:08Z")

</div>

It says my images do not occupy same physical space? Should I resample my image? Is there any other way? Doen’t it effect my registration process if i resample it?

---

<div class="post-metadata">

### Author: ![MrItk](https://discourse.itk.org/user_avatar/discourse.itk.org/mritk/32/1630_2.png) [@MrItk](https://discourse.itk.org/u/MrItk)
#### Post date: [July 14, 2020, 8:00am UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/6 "2020-07-14T08:00:30Z")

</div>

did you found a way to use the demons registration without resampling the images ?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 14, 2020, 1:36pm UTC](https://discourse.itk.org/t/python-code-for-diffeomorphicdemonsregistration-in-simpleitk/1937/7 "2020-07-14T13:36:26Z")

</div>

The implementation of the demons methods assumes that the images occupy the same physical space, so if they don’t you have to resample.

Usually this is in a multi step registration where you have a global (rigid/affine) transformation followed by a demons based registration. The image is resampled using the global transformation and that is used as input for the demons registration. If you use BSpline registration you won’t have to resample.
