Mutual Information Metric#
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.
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.
fixed_image_path = "fixed.png" moving_image_path = "moving.png"
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)
fixed_image = itk.imread(fixed_image_path, itk.F) moving_image = itk.imread(moving_image_path, itk.F)
<itkwidgets.viewer.Viewer at 0x7f82c2c3bc10>