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

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
Best,
Dat

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

Here it is @lassoan. Lots of thanks.
image

image
image
image

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.

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.

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.

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


image
What do you mean by pre-align manually? Thank you.

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.

Thank you very much. I will try again.

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

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
The CochleaRegistrationMask_L volume appeared to be blanked

image.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

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.

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.

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.

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.

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.

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!

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

1 Like

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

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:

1 Like