Is there any difference in performance (in Registration) between python and CSharp in SimpleITK?

I use version 2.2 of simpleitk.
It was implemented by referring to the following code for registration.

https://simpleitk.readthedocs.io/en/master/link_ImageRegistrationMethodBSpline2_docs.html

Previously, image registration was performed using python, and good results were obtained.
However, this time, I tried to registration with the same parameter and the same image using CSharp, and I got a bad result.

In both cases, The main parts are as follows.

transformDomainMeshSize=[10]*moving.GetDimension()
tx = sitk.BSplineTransformInitializer(fixed, transformDomainMeshSize, 3)

R = sitk.ImageRegistrationMethod()
R.SetMetricAsMattesMutualInformation(50)
R.SetOptimizerAsGradientDescentLineSearch(5.0, 100, convergenceMinimumValue=1e-1, convergenceWindowSize=5)
R.SetOptimizerScalesFromPhysicalShift()
R.SetInitialTransform(tx)
R.SetInterpolator(sitk.sitkLinear)

R.SetShrinkFactorsPerLevel([4,2,1])
R.SetSmoothingSigmasPerLevel([4,2,1])

outTx = R.Execute(fixed, moving)

<C#>

        var transformDomainMeshSize = new VectorUInt32();
        transformDomainMeshSize.Add(10);
        transformDomainMeshSize.Add(10);

        var tx = new BSplineTransformInitializerFilter();
        tx.SetTransformDomainMeshSize(transformDomainMeshSize);
        var tx_t = tx.Execute(fixedImage);

        R = new ImageRegistrationMethod();
        R.SetMetricAsMattesMutualInformation(50);
        R.SetOptimizerAsGradientDescentLineSearch(5.0, 100, 1e-1, 5);
        R.SetOptimizerScalesFromPhysicalShift();
        R.SetInitialTransform(tx_t);
        R.SetInterpolator(InterpolatorEnum.sitkLinear);

        VectorUInt32 shrinkFactorsPerLevel = new VectorUInt32(3)
        {
            4,
            2,
            1
        };

        VectorDouble smoothingSigmasPerLevel = new VectorDouble(3)
        {
            4,
            2,
            1
        };

        R.SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
        R.SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);

For other parts, I think the same function and parameter were used.

Is there any difference in performance between python and CSharp in SimpleITK?
Or is it a problem with my code?

Please give me advice.

Hello @jpad,

Under the hood it is the same C++ code for all the wrapped languages.

One thing that may be different is the SetMetricSamplingStrategy setting and the SetMetricSamplingPercentage or SetMetricSamplingPercentagePerLevel settings, not provided in the code so guessing here.

If any of these are different, the registration settings are different. Finally, even when all settings are the same, there is built in variability due to the use of a randomization in the registration. For additional details see the reproducibility section in the registration overview.

1 Like