Why is the final mutual information obtained in the registration process different from the mutual information of the image after I calculate the registration

this is my code

    initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                      moving_image, 
                                                      sitk.Euler3DTransform(), 
                                                      sitk.CenteredTransformInitializerFilter.GEOMETRY)
    registration_method = sitk.ImageRegistrationMethod()

    # Similarity metric settings.
    registration_method.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50)
    # registration_method.SetMetricAsANTSNeighborhoodCorrelation(4)
    registration_method.SetMetricSamplingStrategy(registration_method.RANDOM)
    registration_method.SetMetricSamplingPercentage(0.1,seed=666)#0.01

    registration_method.SetInterpolator(sitk.sitkLinear)

    registration_method.SetOptimizerAsGradientDescent(learningRate=1.0, numberOfIterations=100, 
    convergenceMinimumValue=1e-6, convergenceWindowSize=10)
    registration_method.SetOptimizerScalesFromPhysicalShift()

    # Setup for the multi-resolution framework.            
    registration_method.SetShrinkFactorsPerLevel(shrinkFactors = [4,2,1])
    registration_method.SetSmoothingSigmasPerLevel(smoothingSigmas=[2,1,0])
    registration_method.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()

    # Don't optimize in-place, we would possibly like to run this cell multiple times.
    registration_method.SetInitialTransform(initial_transform, inPlace=False)
    registration_method.SetGlobalDefaultNumberOfThreads(1)

    # registration_method.AddCommand(sitk.sitkStartEvent, start_plot)
    # registration_method.AddCommand(sitk.sitkEndEvent, end_plot)
    # registration_method.AddCommand(sitk.sitkMultiResolutionIterationEvent, update_multires_iterations) 
    # registration_method.AddCommand(sitk.sitkIterationEvent, lambda: plot_values(registration_method))
    print(fixed_image.GetSpacing())
    print(moving_image.GetSpacing())
    final_transform = registration_method.Execute(sitk.Cast(fixed_image,sitk.sitkFloat32),sitk.Cast(moving_image,sitk.sitkFloat32)
                                                )
    wrap_image = sitk.Resample(moving_image, fixed_image, final_transform, sitk.sitkLinear,0, moving_image.GetPixelID())

    print('Final metric value: {0}'.format(registration_method.GetMetricValue()))

    def mi(im1,im2,bin):
        registation=sitk.ImageRegistrationMethod()
        registation.SetMetricAsMattesMutualInformation(numberOfHistogramBins=bin)
        registation.SetMetricSamplingStrategy(registation.NONE)
        registation.SetMetricSamplingPercentage(0.01)
        res=registation.MetricEvaluate(im1,im2)
        return res

Hello @ljjiayou,

Please see this discussion. It answers your question and covers other related registration details.

thanks