SimpeElastix affine registration throws error

Trying to execute an affine registration with SimpleElastix:

elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(t1)
elastixImageFilter.SetMovingImage(fet)
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap("affine"))
elastixImageFilter.LogToFileOn()
elastixImageFilter.Execute()
registered =elastixImageFilter.GetResultImage()

t1 and fet are nii.gz images that are read with sitk.

This gives the following error:

RuntimeError: Exception thrown in SimpleITK ElastixImageFilter_Execute: C:\dafne\SimpleElastix\Code\Elastix\src\sitkElastixImageFilterImpl.cxx:259:
sitk::ERROR: 
itk::ExceptionObject (0000007D575E63C0)
Location: "unknown" 
File: c:\dafne\simpleelastix\build\elastix\core\main\elxElastixFilter.hxx
Line: 253
Description: itk::ERROR: ElastixFilter(000001B31F7DA230): Internal elastix error: See elastix log (use LogToConsoleOn() or LogToFileOn()).

The console log shows:

ELASTIX version: 5.000
Command line options from ElastixBase:
-fMask    unspecified, so no fixed mask used
-mMask    unspecified, so no moving mask used
-out      ./
-priority unspecified, so NORMAL process priority
-threads  unspecified, so all available threads are used
WARNING: The parameter "UseDirectionCosines", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.

WARNING: The option "UseDirectionCosines" was not found in your parameter file.
  From elastix 4.8 it defaults to true!
This may change the behavior of your registrations considerably.

Command line options from TransformBase:
-t0       unspecified, so no initial transform used

Reading images...
Reading images took 0 ms.

WARNING: the fixed pyramid schedule is not fully specified!
  A default pyramid schedule is used.
WARNING: the moving pyramid schedule is not fully specified!
  A default pyramid schedule is used.
WARNING: The parameter "AutomaticTransformInitialization", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "AutomaticTransformInitializationMethod", requested at entry number 0, does not exist at all.
  The default value "GeometricalCenter" is used instead.
Transform parameters are initialized as: [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]
InitializeTransform took 0.00s
Scales are estimated automatically.
Scales for transform parameters are: [2168.0378799856126, 4323.175170872498, 4323.809329029739, 2168.0378799856126, 4323.175170872498, 4323.809329029739, 2168.0378799856126, 4323.175170872498, 4323.809329029739, 1, 1, 1]
Initialization of all components (before registration) took: 10 ms.
Preparation of the image pyramids took: 5720 ms.

Resolution: 0
WARNING: The parameter "ShowExactMetricValue", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "UseMultiThreadingForMetrics", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.
Setting the fixed masks took: 0 ms.
Setting the moving masks took: 0 ms.
WARNING: The parameter "FixedImageBSplineInterpolationOrder", requested at entry number 0, does not exist at all.
  The default value "1" is used instead.
WARNING: The parameter "UseRandomSampleRegion", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "NumberOfHistogramBins", requested at entry number 0, does not exist at all.
  The default value "32" is used instead.
WARNING: The parameter "NumberOfFixedHistogramBins", requested at entry number 0, does not exist at all.
  The default value "32" is used instead.
WARNING: The parameter "NumberOfMovingHistogramBins", requested at entry number 0, does not exist at all.
  The default value "32" is used instead.
WARNING: The parameter "FixedLimitRangeRatio", requested at entry number 0, does not exist at all.
  The default value "0.01" is used instead.
WARNING: The parameter "MovingLimitRangeRatio", requested at entry number 0, does not exist at all.
  The default value "0.01" is used instead.
WARNING: The parameter "FixedKernelBSplineOrder", requested at entry number 0, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "MovingKernelBSplineOrder", requested at entry number 0, does not exist at all.
  The default value "3" is used instead.
WARNING: The parameter "UseFastAndLowMemoryVersion", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseJacobianPreconditioning", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "FiniteDifferenceDerivative", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "SP_A", requested at entry number 0, does not exist at all.
  The default value "20" is used instead.

WARNING: You have set MaximumNumberOfSamplingAttempts to 8.
  This functionality is known to cause problems (stack overflow) for large values.
  If elastix stops or segfaults for no obvious reason, reduce this value.
  You may select the RandomSparseMask image sampler to fix mask-related problems.

WARNING: The parameter "SigmoidInitialTime", requested at entry number 0, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "MaxBandCovSize", requested at entry number 0, does not exist at all.
  The default value "192" is used instead.
WARNING: The parameter "NumberOfBandStructureSamples", requested at entry number 0, does not exist at all.
  The default value "10" is used instead.
WARNING: The parameter "UseAdaptiveStepSizes", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseConstantStep", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "MaximumStepLengthRatio", requested at entry number 0, does not exist at all.
  The default value "1" is used instead.
WARNING: The parameter "MaximumStepLength", requested at entry number 0, does not exist at all.
  The default value "0.759105" is used instead.
WARNING: The parameter "NumberOfGradientMeasurements", requested at entry number 0, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "NumberOfJacobianMeasurements", requested at entry number 0, does not exist at all.
  The default value "1000" is used instead.
WARNING: The parameter "SigmoidScaleFactor", requested at entry number 0, does not exist at all.
  The default value "0.1" is used instead.
Elastix initialization of all components (for this resolution) took: 3 ms.
  Computing the fixed image extrema took 105 ms.
  Computing the moving image extrema took 19 ms.
Initialization of AdvancedMattesMutualInformation metric took: 127 ms.
Starting automatic parameter estimation for AdaptiveStochasticGradientDescent ...
WARNING: The parameter "ASGDParameterEstimationMethod", requested at entry number 0, does not exist at all.
  The default value "Original" is used instead.
  Computing JacobianTerms ...
  Computing the Jacobian terms took 0.003003s
  NumberOfGradientMeasurements to estimate sigma_i: 3
  Sampling gradients ...
Time spent in resolution 0 (ITK initialization and iterating): 0.132 s.
Stopping condition: Error in metric.
Settings of AdaptiveStochasticGradientDescent in resolution 0:
( SP_a 1.000000 )
( SP_A 20.000000 )
( SP_alpha 0.602000 )
( SigmoidMax 1.000000 )
( SigmoidMin -0.800000 )
( SigmoidScale 0.000000 )


itk::ExceptionObject (0000007D575E5F88)
Location: "ElastixTemplate - Run()"
File: c:\dafne\simpleelastix\build\elastix\common\costfunctions\itkAdvancedImageToImageMetric.hxx
Line: 1007
Description: itk::ERROR: AdvancedMattesMutualInformationMetric(000001B337391F80): Too many samples map outside moving image buffer: 0 / 4212


Error occurred during actual registration.

A simple spacial registration works with the following code:

registered = sitk.Elastix(t1, fet)

I can’t quite figure out what I’m doing wrong, any advice?

Maybe @Niels_Dekker could answer? This is probably better asked at some elastix-specific venue, such as elastix-imageregistration group.

Thanks for your question, @KateDelb

There appears an error message in your output saying

There is an elastix FAQ item specifically about that errror message:

I am getting the error message: “Too many samples map outside moving image buffer”. What does that mean?

At FAQ · SuperElastix/elastix Wiki · GitHub

Is that helpful to you?

Kind regards, Niels