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

Retrieve fixed and moving images for registration#

We aim to register two slice images, one of which has an arbitrary offset and rotation. We seek to use an affine transform to appropriately rotate and translate the moving image to register with the fixed image.

[2]:
fixed_image_path = "fixed.png"
moving_image_path = "moving.png"
[3]:
if not os.path.exists(fixed_image_path):
    url = "https://data.kitware.com/api/v1/file/602c10a22fa25629b97d2896/download"
    urlretrieve(url, fixed_image_path)
if not os.path.exists(moving_image_path):
    url = "https://data.kitware.com/api/v1/file/602c10a32fa25629b97d28a0/download"
    urlretrieve(url, moving_image_path)
[5]:
fixed_image = itk.imread(fixed_image_path, itk.F)
moving_image = itk.imread(moving_image_path, itk.F)
[6]:
view(fixed_image)
[6]:
<itkwidgets.viewer.Viewer at 0x7f82c2c3bc10>
[7]:
view(moving_image)