# Cleaning elastix results

**URL:** <https://discourse.slicer.org/t/cleaning-elastix-results/34784>\
**Category:** Support\
**Tags:** registration, elastix\
**Created:** [March 8, 2024, 4:21pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784 "2024-03-08T16:21:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteboo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/matteboo/32/66548_2.png) [@Matteboo](https://discourse.slicer.org/u/Matteboo)\
**Post date:** [March 8, 2024, 4:21pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/1 "2024-03-08T16:21:26Z")

</div>

Hello,

I’ve been trying to use elastix to register some organs but I have a few issue.  
After registration, the results need “cleaning” (see picture where I registered a liver onto itself)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/e/9e2ccb7eb898a973e6ac8fbc6d1ed6911e20a22b.png)  
I can fix it by doing some closing/dilating.

The issue is that I have other structure inside the organ I want to apply the transform to and I fear that my cleaning is changing the volume.

Has anybody encountered a similar issue ?  
Any tips on how to fix this ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 8, 2024, 8:20pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/2 "2024-03-08T20:20:52Z")

</div>

A warped organ should not look like this. Do you do 3D/3D registration?

Did you apply the transform using Transforms module?

Could you please show the dispacement field (in Transforms module, visualization section) and copy the screenshot here? We would see if the field makes sense (smooth and not folding onto itself).

---

<div class="post-metadata">

**Author:** ![Matteboo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/matteboo/32/66548_2.png) [@Matteboo](https://discourse.slicer.org/u/Matteboo)\
**Post date:** [March 11, 2024, 9:05am UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/3 "2024-03-11T09:05:37Z")

</div>

I applied the transform given by elastix using the transform module and I got good results.  
I don’t know why the volume given by the elastix module is different.  
In my project, I’m calling elastix directly (without going through slicer) and I have the same issue.  
Do you know what the transform modul does differently that I could implement on my side.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 11, 2024, 12:13pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/4 "2024-03-11T12:13:33Z")

</div>

> [@Matteboo](#):
>
> I don’t know why the volume given by the elastix module is different.

How did you make the Elastix module transform a segment? What inputs and outputs have you specified?

---

<div class="post-metadata">

**Author:** ![Matteboo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/matteboo/32/66548_2.png) [@Matteboo](https://discourse.slicer.org/u/Matteboo)\
**Post date:** [March 11, 2024, 12:18pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/5 "2024-03-11T12:18:19Z")

</div>

I put the same volume as input and output.  
It’s a the segmentation of a liver, stocked as a .nii, that I imported in slicer as a volume.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/4/946ff997975d8cdc65ea0b14bd75018e79b4f8a8.png)  
I was using the output volume area on for the screenshot I provided in my first message  
My guess is that the transform module does some kind of pre/post processing that is absent in the elastix module.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 11, 2024, 12:31pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/6 "2024-03-11T12:31:21Z")

</div>

You cannot choose the same volume as input and output, because you cannot use a label volume directly as fixed or moving volume. The registration would not reliably converge due to large homogeneous regions in the label image. You could compute distance maps from binary images and use thise as registration inputs (this is implemented in [Segment Registration](https://slicer.readthedocs.io/en/latest/user_guide/registration.html#segmentation-and-binary-image-registration)) or maybe use some special metric that includes a similar processing (but I don’t know if Elastix provides something like this).

---

<div class="post-metadata">

**Author:** ![Matteboo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/matteboo/32/66548_2.png) [@Matteboo](https://discourse.slicer.org/u/Matteboo)\
**Post date:** [March 11, 2024, 1:03pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/7 "2024-03-11T13:03:25Z")

</div>

I understand your point. However, in practice, Now that I apply the registration with the transform module, everything works well. I’ll look into changing my pipeline to have something more theoretically correct in the fututre.  
The issue didn’t seem to come from the transform in itself but from the way it is applied in the elastix module.  
Your advice allowed me to find a solution and highlighted potential weak point in my approach, thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![Matteboo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/matteboo/32/66548_2.png) [@Matteboo](https://discourse.slicer.org/u/Matteboo)\
**Post date:** [March 15, 2024, 1:59pm UTC](https://discourse.slicer.org/t/cleaning-elastix-results/34784/8 "2024-03-15T13:59:26Z")

</div>

As suggested by @lassoan, the solution to my issue was to apply the transform given by the elastix modul to my volume **using the transform module**.  
The cause of the issue seems to be transformix (the part of elastix in charge to apply the transform). The way transformix and the transform module apply the transform are different.  
If someone has an explanation of this difference, I’m curious to know.
