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.

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

fixed_img_path = "BrainT1SliceBorder20.png"
moving_img_path = "BrainProtonDensitySliceShifted13x17y.png"
if not os.path.exists(fixed_img_path):
    url = ""
    urlretrieve(url, fixed_img_path)
if not os.path.exists(moving_img_path):
    url = ""
    urlretrieve(url, moving_img_path)
fixed_img = itk.imread("BrainT1SliceBorder20.png", itk.F)
moving_img = itk.imread("BrainProtonDensitySliceShifted13x17y.png", itk.F)
<itkwidgets.viewer.Viewer at 0x7f244ecbcfa0>