# It's been chaotic lately. My purpose is to calculate the normalized mutual information of pre-registration and post-registration images, and make a comparison to observe the registration effect.

It’s been chaotic lately.
My purpose is to calculate the normalized mutual information of pre-registration and post-registration images, and make a comparison to observe the registration effect.
This is my code for calculating normalized mutual information:

``````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
``````

For the unregistered image, because the spatial position does not match, I will go first
fixed_image.setorigin(moving_image.getorigin())
Then calculate the mutual information according to the above function.
My questions are: first, whether the above function computes normalized mutual information or non-normalized mutual information; Second: if I input two identical images into the function, the result is greater than 1, and the result of my image registration is about 0.8, I don’t understand, if two images are the same, shouldn’t the value obtained be 1
If my calculation method is wrong, how can I write code to calculate the mutual information before and after registration and then compare it?

Hello @ljjiayou,

The value computed in ITK/SimpleITK is mutual information (not normalized).

The bounds on MI were provided in the response to one of your previous questions.

Even if two images are exactly the same the MI will most often not be 1, please look at the MI formula, equation 1 on that page, to gain a better understanding of this similarity metric.

Comparing MI before and after registration will only show you that the registration is minimizing the negative mutual information (value after registration will be lower than before, ITK/SimpleITK works with -MI). Please do not use MI to quantify the quality of the registration, it is not reliable (for details see the paper by T. Rohlfing).