this is my code:

registation=sitk.ImageRegistrationMethod()

registation.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50)

registation.SetMetricSamplingStrategy(registation.NONE)

registation.SetMetricSamplingPercentage(0.01)

res=registation.MetricEvaluate(im1,im2)

Hello @ljjiayou,

The range for mutual information is bound from below by zero, when the two variables are independent. It is bound from above by log(min(cardinality(X), cardinality(Y))), when the values in X and Y are equally likely.

Note that in ITK we use the negative of MI, because similarity measures are minimized.

thanks. But when I calculate the mutual information between two images that are not registered, I get an error. why?

like this:

RuntimeError: Exception thrown in SimpleITK ImageRegistrationMethod_MetricEvaluate: [d:\a\1\sitk-build\itk-prefix\include\itk-5.3\itkMattesMutualInformationImageToImageMetricv4.hxx:311](file:///D:/a/1/sitk-build/itk-prefix/include/itk-5.3/itkMattesMutualInformationImageToImageMetricv4.hxx:311): ITK ERROR: MattesMutualInformationImageToImageMetricv4(0000029879020880): All samples map outside moving image buffer. The images do not sufficiently overlap. They need to be initialized to have more overlap before this metric will work. For instance, you can align the image centers by translation.

Hello @ljjiayou,

The error message is clear, the two images have insufficient or no overlap, so we cannot compute the mutual information (MI). To compute the MI, points mapped from the fixed image coordinate system via a transformation need to be inside the moving image’s spatial domain. If you do not initialize the transformation correctly none of them are mapping inside the moving image and hence we cannot compute the MI.

Please read the registration overview and see the set of jupyter notebooks (series starting with 6*) which illustrate the various aspects of registration.