# mutual information entropy

**URL:** https://discourse.itk.org/t/mutual-information-entropy/3341
**Category:** Algorithms
**Tags:** registration, python, simpleitk
**Created:** [July 29, 2020, 9:12am UTC](https://discourse.itk.org/t/mutual-information-entropy/3341 "2020-07-29T09:12:44Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![TJH123456](https://discourse.itk.org/user_avatar/discourse.itk.org/tjh123456/32/1654_2.png) [@TJH123456](https://discourse.itk.org/u/TJH123456)
#### Post date: [July 29, 2020, 9:12am UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/1 "2020-07-29T09:12:44Z")

</div>

Hello

I want to ask that in the metrics class of sklearn package, [mutual\_ info\_ score] is used to calculate Shannon’s mutual information entropy? If not, is there any way to calculate it? If so, is it accurate? Because I need to calculate the mutual information entropy of two images.

Thank you for your answers.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [July 29, 2020, 1:03pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/2 "2020-07-29T13:03:30Z")

</div>

You should look into [MutualInformation](https://itk.org/Doxygen/html/classitk_1_1MutualInformationImageToImageMetric.html) and [MattesMutualInformation](https://itk.org/Doxygen/html/classitk_1_1MattesMutualInformationImageToImageMetric.html) and perhaps other [image similarity metrics](https://itk.org/Doxygen/html/group__RegistrationMetrics.html). To evaluate a metric directly (outside of registration framework), look at [this example](https://itk.org/ITKExamples/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Documentation.html).

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 29, 2020, 1:09pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/3 "2020-07-29T13:09:16Z")

</div>

Hello @TJH123456,

Please keep variations of the same question in the same thread (your previous variant [rotate the image](https://discourse.itk.org/t/rotate-the-image/3340/2) which was answered there).

---

<div class="post-metadata">

### Author: ![TJH123456](https://discourse.itk.org/user_avatar/discourse.itk.org/tjh123456/32/1654_2.png) [@TJH123456](https://discourse.itk.org/u/TJH123456)
#### Post date: [August 11, 2020, 11:29am UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/4 "2020-08-11T11:29:05Z")

</div>

Hello, I have an idea, but I don’t know if it can be realized.

I want to import the image into the framework, and only calculate the similarity without other steps. Is this feasible?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [August 11, 2020, 12:51pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/5 "2020-08-11T12:51:35Z")

</div>

Hello @TJH123456,

Yes, this can be done using the `MetricEvaluate` method. Please see [this Jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/63_Registration_Initialization.ipynb) section titled “MetricEvaluate”.

---

<div class="post-metadata">

### Author: ![TJH123456](https://discourse.itk.org/user_avatar/discourse.itk.org/tjh123456/32/1654_2.png) [@TJH123456](https://discourse.itk.org/u/TJH123456)
#### Post date: [August 11, 2020, 1:10pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/6 "2020-08-11T13:10:54Z")

</div>

Thank you for your answer. But I found that it has interpolation function, and all I want is to calculate the similarity value of two images. I delete a part of the code, I do not know if the function I achieve after doing so is correct?I hope you can help me to have a look.Thanks.

 ![image](https://discourse.itk.org/uploads/default/original/2X/2/266a4986090aa6d26540dc88cfe684dad5b267bb.png)

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [August 11, 2020, 1:33pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/7 "2020-08-11T13:33:45Z")

</div>

Hello @TJH123456,  
We always use an interpolator as the computation is configured for a generic setting, not one where the two images have been resampled onto each other, which I assume is your case. Given this assumption, you can: (1) set interpolator to nearest neighbor (2) not do sampling, `SetMetricSamplingStrategy(registration\_method.NONE) (3) set the transformation to the identity.

---

<div class="post-metadata">

### Author: ![TJH123456](https://discourse.itk.org/user_avatar/discourse.itk.org/tjh123456/32/1654_2.png) [@TJH123456](https://discourse.itk.org/u/TJH123456)
#### Post date: [August 11, 2020, 1:53pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/8 "2020-08-11T13:53:27Z")

</div>

Thank you very much for your reply!

After reading the link you provided, I also found that the unit of display angle can be set as degree (°), instead of radian. In this way, can I input the value in the unit of angle directly when setting parameters?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [August 11, 2020, 1:59pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/9 "2020-08-11T13:59:35Z")

</div>

Hello @TJH123456,  
The angles are always given in radians. If you want to work in degrees simply use `numpy.radians` to do the conversion.

---

<div class="post-metadata">

### Author: ![TJH123456](https://discourse.itk.org/user_avatar/discourse.itk.org/tjh123456/32/1654_2.png) [@TJH123456](https://discourse.itk.org/u/TJH123456)
#### Post date: [August 11, 2020, 2:04pm UTC](https://discourse.itk.org/t/mutual-information-entropy/3341/10 "2020-08-11T14:04:12Z")

</div>

Thank you for your answer! I really appreciate your help. Thank you.
