# Elastix registration fails: Too many samples map outside moving image buffer

**URL:** <https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798>\
**Category:** Support\
**Tags:** registration, elastix\
**Created:** [February 2, 2021, 3:50pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798 "2021-02-02T15:50:15Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 2, 2021, 3:50pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/1 "2021-02-02T15:50:15Z")

</div>

Dear Andras @lassoan .  
I’m segmenting temporal bone using ABL Temporal Bone Segmentation. I stuck at step 2: Rigid registration. When I apply Rigid registration, the process stopped at 14% and it said: “command ‘elastix’ returned non-zero exit status 1”. I’ve installed SlicerElastix, Slicer version 4.11.20200930. Thanks in advance

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/ba38fdd57c2d745680abf78370781d94dd775175.png)  
Best,  
Dat

---

<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:** [February 2, 2021, 4:41pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/2 "2021-02-02T16:41:36Z")

</div>

Do you see any details about the error in the application log?

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 2, 2021, 11:01pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/3 "2021-02-02T23:01:17Z")

</div>

Here it is @lassoan. Lots of thanks.

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

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 2, 2021, 11:06pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/4 "2021-02-02T23:06:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/5/357d9bada86947674dc938fd9a8e4292fe7ce9c0.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/e/7e2a104df9fe637a40dc98c77fc94d6454d0d0a3.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/8/b88580d6baf45707cfc4549c941537e233715cfb.png)

---

<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:** [February 2, 2021, 11:10pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/5 "2021-02-02T23:10:26Z")

</div>

The messages are not visible in these screenshots. Instead of posting pictures, could you copy here the log message text (in menu: Help / Report a bug)? Thank you.

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 5, 2021, 12:53pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/6 "2021-02-05T12:53:56Z")

</div>

Dear Andras. Here is the message log. It’s too long. I’ve deleted some parts. Please take a look at it. Thank you very much.

“ABLTemporalBoneSegmentationModule”  
[INFO][Python] 05.02.2021 19:34:26 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) - Stopping condition: Error in metric.

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Stopping condition: Error in metric.

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Stopping condition: Error in metric.

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) - Settings of AdaptiveStochasticGradientDescent in resolution 0:

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Settings of AdaptiveStochasticGradientDescent in resolution 0:

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) - Description: itk::ERROR: itk::ERROR: AdvancedMattesMutualInformationMetric(000002BF54164290): Too many samples map outside moving image buffer: 188 / 1117

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Description: itk::ERROR: itk::ERROR: AdvancedMattesMutualInformationMetric(000002BF54164290): Too many samples map outside moving image buffer: 188 / 1117

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Description: itk::ERROR: itk::ERROR: AdvancedMattesMutualInformationMetric(000002BF54164290): Too many samples map outside moving image buffer: 188 / 1117

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) - Error occurred during actual registration.

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Error occurred during actual registration.

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Error occurred during actual registration.

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) -

[INFO][Python] 05.02.2021 19:34:27 [Python] (C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py:392) - Errors occurred!

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Errors occurred!

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Errors occurred!

[INFO][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Error: Command ‘elastix’ returned non-zero exit status 1.

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - Traceback (most recent call last):

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - File “C:/Users/USER/AppData/Roaming/NA-MIC/Extensions-29402/ABLTemporalBoneSegmentation/lib/Slicer-4.11/qt-scripted-modules/ABLTemporalBoneSegmentationModule.py”, line 635, in process\_transform

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - output = function()

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - File “C:/Users/USER/AppData/Roaming/NA-MIC/Extensions-29402/ABLTemporalBoneSegmentation/lib/Slicer-4.11/qt-scripted-modules/ABLTemporalBoneSegmentationModule.py”, line 812, in transform

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - log\_callback=self.update\_rigid\_progress)

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - File “C:/Users/USER/AppData/Roaming/NA-MIC/Extensions-29402/ABLTemporalBoneSegmentation/lib/Slicer-4.11/qt-scripted-modules/ABLTemporalBoneSegmentationModule.py”, line 1318, in apply\_elastix\_rigid\_registration

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - movingVolumeMaskNode=mask\_node

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - File “C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py”, line 807, in registerVolumes

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - self.logProcessOutput(ep)

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - File “C:\Users\USER\AppData\Roaming\NA-MIC\Extensions-29402\SlicerElastix\lib\Slicer-4.11\qt-scripted-modules\Elastix.py”, line 728, in logProcessOutput

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - raise subprocess.CalledProcessError(return\_code, “elastix”)

[CRITICAL][Stream] 05.02.2021 19:34:27 [] (unknown:0) - subprocess.CalledProcessError: Command ‘elastix’ returned non-zero exit status 1.

---

<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:** [February 5, 2021, 3:35pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/7 "2021-02-05T15:35:25Z")

</div>

> [@DAT\_Minh](#):
>
> Too many samples map outside moving image buffer: 188 / 1117

This is probably the most common image registration error and it means that the two volumes are too far from each other, so it is not possible to compute the similarity metric. This usually happens when the input images in their initial position do not sufficiently overlap (but rarely it can happen when the registration completely diverges).

One solution is to use an initialization step that automatically pre-aligns the input volumes. I think the default preset contains such a step (it uses center of gravity to align the position, maybe also moments to align the orientation), which works well if the two input volumes are cropped to approximately to the same region.

If automatic initialization fails then you can pre-align manually, using a very quick fiducial registration using 3-5 points.

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 6, 2021, 11:29am UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/8 "2021-02-06T11:29:51Z")

</div>

Dear Andras. I used two methods of alignment shown in the yellow circle in the pictures attached. None of them work.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/6/d690204f9d3556bbb3034e8bfa12cf63a99fdee1.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/4/c47748a0d78a0a49ca1e65c5a78498e1e15c48c7.jpeg)  
What do you mean by pre-align manually? Thank you.

---

<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:** [February 6, 2021, 2:01pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/9 "2021-02-06T14:01:13Z")

</div>

Zooming in/out the slice view (“Adjust the field of view…” button) does not change the images or their alignments. It has no effect on registration.

What you may need to do is to transform the image with manual or semi-automatic registration methods before running the automatic method; crop the images to the same region (not just zoom in the view but actually crop, using Crop volume module). See details [here](https://slicer.readthedocs.io/en/latest/user_guide/registration.html#automatic-image-registration).

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 6, 2021, 2:59pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/10 "2021-02-06T14:59:06Z")

</div>

Thank you very much. I will try again.

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 6, 2021, 5:09pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/11 "2021-02-06T17:09:04Z")

</div>

Dear Andras, I have a few questions:  
I tried to pre-align the Left temporal volume with Atlas\_L volume. In the ABL temporal bone segmentation module, Atlas\_L exist as a volume (picture):

 ![image.jpg](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/2/22ed2c4be7e9649e86db5b61041267e12fde74a0.jpeg)

But when I turned to Data module, Atlas\_L module does not appear as a volume, but CochleaRegistrationMask\_L. When I toggle off CochleaRegistrationMask\_L volume, Atlas\_L turns on and reverse.  
 ![image.jpg](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/a/5a93068295f53c1e73a3cd36766f0392b5c814bf.jpeg)  
The CochleaRegistrationMask\_L volume appeared to be blanked

![image.png](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/7/e71a5065f42c78a7b33b21e0502cd7c4e1506a91.png)

I tried to register Left temporal volume with CochleaRegistrationMask\_L volume (the latter is supposed to be Atlas\_L volume, however, Atlas\_L didn’t appear as a volume in Data) using Landmarks registration, CochleaRegistrationMask\_L volume is completely black.

![image.jpg](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/1/b1999b25f593e476f3683f6bd623f282f45502ef.jpeg)

So my question is: which volume to register with? Why the Atlas\_L volume does not appear in Data module? Lots of thanks for your help.

---

<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:** [February 6, 2021, 5:47pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/12 "2021-02-06T17:47:44Z")

</div>

When the slice view is all black then it means that it shows a region that is outside the volume’s region. Landmark registration module is good for refining alignment when two volumes are already approximately aligned. You can use Fiducial Registration Wizard module to align volumes that are very far from each other.

@pieper It would be great if you could update Landmark Registration module to allow independent point placement on the two volumes (this is particularly important for the first point, and if orientation is very different then for the first 3 points), because if the two volumes are at very different places then the current module is not usable by itself.

---

<div class="post-metadata">

**Author:** ![DAT\_Minh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dat_minh/32/9097_2.png) [@DAT\_Minh](https://discourse.slicer.org/u/DAT_Minh)\
**Post date:** [February 7, 2021, 10:15am UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/13 "2021-02-07T10:15:39Z")

</div>

Dear Andras. Which volume to pre-align left temporal volume with (Atlas\_L or CochleaRegistrationMask\_L volume) before doing rigid registration in ABL temporal bone segmentation module? Does it mean that we have to register the input image twice in order the computer to understand?  
Atlas\_L volume is not shown in Data. I can’t pre-register input volume with it  
I still can’t see the solution. Please help. Can you do an example. Thanks.

---

<div class="post-metadata">

**Author:** ![bonniezyao](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bonniezyao/32/16450_2.png) [@bonniezyao](https://discourse.slicer.org/u/bonniezyao)\
**Post date:** [August 30, 2022, 6:47pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/14 "2022-08-30T18:47:35Z")

</div>

> [@lassoan](#):
>
> fiducial

Hi.  
I have been using elastix via the command line package trying to register two stacks of images (mice brain serial imaging). I was able to use affine transform between my datasets. And I want to use a bspline transformation to obtain more precise registration with sub-regions. I encountered the same error message as this thread, even though the fixed image is the result from the affine transformation.  
I was wondering if I could do anything like the suggested manual alignment with the command line package, or should I use 3D slicer for this?

Thanks!  
Bonnie Zhiyi Yao

Command window:  
itk::ExceptionObject (0x556ff4159750)  
Location: “ElastixTemplate - Run()”  
File: /home/niels\_dekker/dev/src/elastix/Common/CostFunctions/itkAdvancedImageToImageMetric.hxx  
Line: 1006  
Description: itk::ERROR: itk::ERROR: AdvancedMattesMutualInformationMetric(0x556ff411dd70): Too many samples map outside moving image buffer: 621 / 3000

Error occurred during actual registration.

---

<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:** [August 30, 2022, 6:51pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/15 "2022-08-30T18:51:25Z")

</div>

This error message means that the two input images do not overlap sufficiently enough. Make sure you harden the transform on the input images before starting the registration.

---

<div class="post-metadata">

**Author:** ![bonniezyao](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bonniezyao/32/16450_2.png) [@bonniezyao](https://discourse.slicer.org/u/bonniezyao)\
**Post date:** [August 30, 2022, 8:41pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/16 "2022-08-30T20:41:08Z")

</div>

That’s a feature only available in the 3D slicer software, and is not a command line option, correct? I think since I used the constructed images from the affine transformation, the original nodes information wouldn’t be involved?

Thanks for the speedy reply!

---

<div class="post-metadata">

**Author:** ![bonniezyao](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bonniezyao/32/16450_2.png) [@bonniezyao](https://discourse.slicer.org/u/bonniezyao)\
**Post date:** [August 30, 2022, 9:08pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/17 "2022-08-30T21:08:51Z")

</div>

Actually, I didn’t have the correct output files as the moving image. Problem solved! Thank you again!

---

<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:** [August 30, 2022, 9:10pm UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/18 "2022-08-30T21:10:45Z")

</div>

Hardening an affine transform on an image is a one-click operation in Slicer. It is also available via Python scripting (and since you can run Python commands via command line, the feature is available from the console, too).

---

<div class="post-metadata">

**Author:** ![evan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/evan/32/4953_2.png) [@evan](https://discourse.slicer.org/u/evan)\
**Post date:** [December 10, 2022, 12:00am UTC](https://discourse.slicer.org/t/elastix-registration-fails-too-many-samples-map-outside-moving-image-buffer/15798/19 "2022-12-10T00:00:15Z")

</div>

Thank you to everyone who contributed on this thread and for the work of @lassoan.

I will be using the following GitHub Issue to track the issue that @DAT_Minh mentioned:

> <https://github.com/Auditory-Biophysics-Lab/Slicer-ABLTemporalBoneSegmentation/issues/8>
>
> I was excited when I found out about this module, and thank you for all your wor…k. Currently I'm stuck at step 2 and I got the error message saying: 
> "command elsatix return to non-zero exit status 1 error."
> 
> \<img width="1503" alt="Screenshot 2022-11-30 at 14 18 11" src="https://user-images.githubusercontent.com/61168470/204880516-399145d8-ca63-4acb-aed8-c750e1a850d9.png"\>
> 
> Any help is greatly appreciated. 
> @ben-connors @jamesobutler @e-simpson
