# Elastix registration with Masking

**URL:** <https://discourse.slicer.org/t/elastix-registration-with-masking/37556>\
**Category:** Support\
**Tags:** registration\
**Created:** [July 25, 2024, 9:54am UTC](https://discourse.slicer.org/t/elastix-registration-with-masking/37556 "2024-07-25T09:54:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![khajta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/khajta/32/76581_2.png) [@khajta](https://discourse.slicer.org/u/khajta)\
**Post date:** [July 25, 2024, 9:54am UTC](https://discourse.slicer.org/t/elastix-registration-with-masking/37556/1 "2024-07-25T09:54:08Z")

</div>

Dear experts,  
I would like to register 2 images, CT and CT. Actually, my final goal is to register SPECT and SPECT with different timepoint.

Firstly, I used rigid registration followed by elastix between CT1 and CT2 at different timepoint. Then I use these transformation matrices to SPECT2. The result looked well for organ but not tumor. I would like to use masking in elastix. I apply segmented tumor. The result showed error.

Failed to compute results.

Command ‘elastix’ returned non-zero exit status 1.

Traceback (most recent call last):  
File “D:\slicer\Slicer 5.6.2\bin\Python\slicer\util.py”, line 3255, in tryWithErrorDisplay  
yield  
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 314, in onApplyButton  
self.logic.registerVolumesUsingParameterNode(self.\_parameterNode)  
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 591, in registerVolumesUsingParameterNode  
self.registerVolumes(  
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 637, in registerVolumes  
self.logProcessOutput(elastixProcess)  
File “D:/slicer/Slicer 5.6.2/slicer.org/Extensions-32448/SlicerElastix/lib/Slicer-5.6/qt-scripted-modules/Elastix.py”, line 572, in logProcessOutput  
raise subprocess.CalledProcessError(return\_code, “elastix”)  
subprocess.CalledProcessError: Command ‘elastix’ returned non-zero exit status 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:** [July 25, 2024, 10:01am UTC](https://discourse.slicer.org/t/elastix-registration-with-masking/37556/2 "2024-07-25T10:01:56Z")

</div>

This means that the error is inside elastix  
To get a better understanding of the error, you need to read the elastix log.  
To do that, tick the “keep temporary files” box, launch your regisrtration then click on “show temp folder”  
There’s a text file called elastix, if you go to the bottom of the file, you should get a more helpfull error

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/3/134c6a1999e3cbb32aa06b21fa68ed5ef836671a.png)

---

<div class="post-metadata">

**Author:** ![khajta](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/khajta/32/76581_2.png) [@khajta](https://discourse.slicer.org/u/khajta)\
**Post date:** [July 26, 2024, 3:31am UTC](https://discourse.slicer.org/t/elastix-registration-with-masking/37556/3 "2024-07-26T03:31:43Z")

</div>

Thank you for your reply.

The text file showed

itk::ExceptionObject (0000003B772FC9B0)  
Location: “ElastixTemplate - Run()”  
File: D:\D\S\S-0-E-b\SlicerElastix-build\elastix\Common\CostFunctions\itkAdvancedImageToImageMetric.hxx  
Line: 916  
Description: ITK ERROR: AdvancedMattesMutualInformationMetric(0000020314FC7190): Too many samples map outside moving image buffer: 510 / 2048

Error occurred during actual registration.

Errors occurred!

---

<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:** [July 29, 2024, 12:37pm UTC](https://discourse.slicer.org/t/elastix-registration-with-masking/37556/4 "2024-07-29T12:37:22Z")

</div>

It’s hard to help you without example, but you can try these:

- Center both of your volume (giving them the same origin)
- Make sure that your volumes are of similar sizes
