# Mutual Information Metric#

The `MutualInformationImageToImageMetric` class computes the mutual information between two images, i.e. the degree to which information content in one image is dependent on the other image. This example shows how `MutualInformationImageToImageMetric` can be used to map transformation parameters and register two images using a gradient ascent algorithm.

```[1]:
```
```import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from urllib.request import urlretrieve

import itk
from itkwidgets import view
```
```[2]:
```
```dim = 2
ImageType = itk.Image[itk.F, dim]
FixedImageType = ImageType
MovingImageType = ImageType
```

## Retrieve fixed and moving images for registration#

We aim to register two slice images, one of which has an arbitrary offset.

```[3]:
```
```fixed_img_path = "BrainT1SliceBorder20.png"
moving_img_path = "BrainProtonDensitySliceShifted13x17y.png"
```
```[4]:
```
```if not os.path.exists(fixed_img_path):
url = "https://data.kitware.com/api/v1/file/5cad1ae88d777f072b18183d/download"
urlretrieve(url, fixed_img_path)
if not os.path.exists(moving_img_path):
url = "https://data.kitware.com/api/v1/file/5cad1ae88d777f072b181831/download"
urlretrieve(url, moving_img_path)
```
```[5]:
```
```fixed_img = itk.imread("BrainT1SliceBorder20.png", itk.F)
moving_img = itk.imread("BrainProtonDensitySliceShifted13x17y.png", itk.F)
```
```[6]:
```
```view(fixed_img)
```
```[6]:
```
```<itkwidgets.viewer.Viewer at 0x7f244ecbcfa0>
```
```[7]:
```
```view(moving_img)
```