SimpleITK ExhaustiveOptimizerv4 Error

Hello, I am trying to use ExhaustiveOptimizer to find a good-ish initial displacement field transform between multimodal 2D images. But it looks like it is impossible to assign Optimizer Scales in any way. I’ve tried
R.SetOptimizerScales(scales) with a suitably sized array, as well as R.SetOptimizerScalesFromJacobian() and other similar methods, always getting the same error.

Below is a snippet of code and the error message:


R = sitk.ImageRegistrationMethod()
R.SetMetricAsMattesMutualInformation(50)
R.SetMetricSamplingStrategy(R.REGULAR)
R.SetMetricSamplingPercentage(0.25)
R.MetricUseFixedImageGradientFilterOff()
displacementField = sitk.Image(fixed.GetSize(), sitk.sitkVectorFloat64)
displacementField.CopyInformation(fixed)
displacementTx = sitk.DisplacementFieldTransform(displacementField)
del displacementField
displacementTx.SetSmoothingGaussianOnUpdate(varianceForUpdateField=0.0,
                                             varianceForTotalField=1.5)
R.SetInitialTransform(displacementTx, inPlace=True)
numParams = displacementTx.GetNumberOfParameters()
print(numParams) # output: 46080
numberOfSteps = [10]*numParams
stepLength = 2
scales = [1]*numParams
R.SetOptimizerAsExhaustive(numberOfSteps=numberOfSteps, stepLength=stepLength)
print(len(scales)) # output: 46080
R.SetOptimizerScales(scales)
#R.SetOptimizerScalesFromJacobian() # gives the same error
R.SetInterpolator(sitk.sitkLinear)
displacementTx = R.Execute(fixed,moving)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_20096/376383059.py in <module>
      8 R.SetOptimizerScalesFromPhysicalShift()
      9 R.SetInterpolator(sitk.sitkLinear)
---> 10 displacementTx = R.Execute(fixed,moving)

~\Miniconda3\envs\dev\lib\site-packages\SimpleITK\SimpleITK.py in Execute(self, fixed, moving)
   6693     def Execute(self, fixed, moving):
   6694         r"""Execute(ImageRegistrationMethod self, Image fixed, Image moving) -> Transform"""
-> 6695         return _SimpleITK.ImageRegistrationMethod_Execute(self, fixed, moving)
   6696 
   6697     def MetricEvaluate(self, fixed, moving):

RuntimeError: Exception thrown in SimpleITK ImageRegistrationMethod_Execute: d:\a\1\sitk-build\itk-prefix\include\itk-5.1\itkExhaustiveOptimizerv4.hxx:82:
itk::ERROR: itk::ERROR: ExhaustiveOptimizerv4(0000013A34F97400): The size of Scales is 2, but the NumberOfParameters is 46080.

The error comes form here:

Have you tried making the scales with length of 2, e.g. scales = [1, 1]?