The problem of image registration consists of aligning two images taken from different perspectives in order to obtain a larger visual representation of some large structure. For instance, one can stitch several overlapping aerial pictures to obtain the map of an entire city. Another example is the creation of panoramic pictures, which consists of stitching pictures taken by rotating the camera. The registration problem is also present in the medical fields. It is required to register medical imagery in order to accurately perform diagnostics as well as detect changes during several types of treatments.

With such a broad spectrum of applications, one can expect the registration problem to be presented with countless particularities. The signals being registered can have an arbitrary amount of dimensions; they might not even contain the same representation of the structure being mapped in the first place. The data from an MRI (representing soft tissues) can be registered with CT scans (more sensitive to high density objects); one may also attempt to register satellite imagery with cartographic maps.

The objective of this article is to gently introduce how the registration problem can be addressed with a non-linear optimization framework, from the Taylor series until the formulation of the Homography Jacobian and Hessian. In this article, we will focus on rigid registration, although the concepts herein can also be applied to the non-rigid case.

## Mathematical formulation

The image registration problem consists of finding the coefficients of the coordinate transforming function such that

Here is the explanation for each element in this formula:

- and are the images being registered.
- has as many dimensions as the input images. When dealing with 2D images, is a 2D vector .
- The coordinate transforming function is just a transformation for a coordinate . Some examples of such transforms are the translation, scale, rotation, sheering, etc. Although it can be arbitrarily complex, we shall focus on the Homography transform later on.
- The vector corresponds to the parameters of the function , and therefore contains as many elements as the number of parameters that requires. For instance, a translation contains two parameters , while a rotation might be represented by a scalar and a rotation axis . We shall see another example when formulating the Homography transform later.
- While the symbols and represent two images, the expressions and represent the evaluation of the pixel intensities at coordinate of image and coordinate of image , respectively.
- is a shorthand for the intersection between the image and the transformed image . Therefore, the summation accounts for all coordinates that belong to the intersection between and the transformed . In other words, must lie within and must lie within .
- is a similarity function. It is high when its parameters are similar, and low when its parameters are different. There are many ways to measure similarity between images, such as sum of absolute differences (SAD), sum of squared differences (SSD), normalized cross correlation (NCC), etc. Later on, we shall focus on the Mutual Information metric.
- Finally, the vector corresponds to the parameters of that maximize the similarity between images and . In other words, it defines the transformation to be applied to image that will maximize its alignment to image .

Note that the image similarity function is expected to have a lowest upper bound. In other words, there is a maximum theoretical possible value that the similarity function may return; the images can’t simply be more similar than that. There might be the case in which many different transform parameters make the similarity function return that value, but no transformation parameter should get you beyond that level of similarity.

## Newton Method for non-linear optimization

In order to understand the Newton algorithm for non-linear optimization, consider the 1D example function below:

As our goal is to reach the global maximum of any arbitrary similarity function , it seems prudent to first have a practical tool for detecting maxima points in the first place. One such a tool consists of looking for points whose slope is zero:

Since the slope of is given by its derivative with respect to the parameters being optimized, , the maxima points can be found as the solution to the following system:

In many practical applications, including the image registration problem, the solution to this system can’t be found analytically. This is where we use Newton’s method for finding roots of differentiable functions.

The idea of Newton’s method for solving is to iteratively approach the solution , starting at any initial guess and skipping to a better point , which is given by the intersection between the line that is tangent to and the horizontal axis, as shown in the figure below.

Since this line is tangent to , its slope must be . As a line, its equation is given by . Since it evaluates to at , then . Finally, since is located at the intersection between this line and , we can find :

This very same procedure can be repeated to compute an , by using as its own initial guess, and an after that. Generalizing, each new point in the iterative scheme can be determined by

until some convergence criteria is satisfied (for instance, until ).

Since , we can finally reach the formulation to each iteration of the Newton’s method for finding a local minimum of , starting at an arbitrary initial guess :

There are a few caveats to this method, though. Notice how the example function contains both *minima* and *maxima*, and the slope of is zero at all of them. The Newton method may converge to *any* of these inflection points, so you must check upon convergence whether you’ve reached a maximum or a minimum inflection point by verifying the signal of , where is the convergence point. If , then you’ve reached a local minimum; if , then you have found a local maximum. If, however, , then the test is inconclusive and might not even be either maximum nor minimum! For instance, consider the function , evaluated at : this inflection point is not interesting at all for our purpose.

## Taylor Series: Approximating functions by polynomials

In the next section, we will talk about the geometrical interpretation of the Newton method. Before we do so, let’s back up a little and recall the concept of Taylor Series. Assuming that the function is infinitely differentiable at , we can write it as an infinite polynomial:

The coefficients of such polynomial can be computed by taking the derivatives of and evaluating them at:&& \omit\rlap{\ldots} \\

Therefore, we have

Let’s take a moment to contemplate the implications of this concept. It is clear that the Taylor series will represent our arbitrary function when all of its infinite terms are present. Nevertheless, it is interesting to see what happens in the case when only its first terms are used to describe an approximation of via a finite polynomial . When , and is only a horizontal line that crosses at .

When , however, something interesting starts to happen. Since in this case , then we can say that the derivative has the same value of the derivative when . That is, is the tangent of at .

By using this very same reasoning, we can say that every additional term included in our Taylor series will make smoothly approximate at down to an additional derivative. In other words, we can find a polynomial of arbitrary degrees that shall smoothly approximate the original function at .

Naturally, the real power of the Taylor series comes when it is adapted to perform such approximation at any arbitrary location of the axis, not just the origin. To achieve this adaptation, we need a polynomial such that

By making and exploring the relationships in , we can find by computing the n-th derivative of as follows:

Finally, we have that the polynomial of degree that smoothly approximates at is given by

## Geometrical Interpretation of the Newton method

Once again, let be a function whose minimum (or maximum) we want to find. Also, let be the initial guess that will be used by the Newton’s method.

Each iteration of the Newton’s method corresponds to finding the second degree Taylor series that approximates at , and defining the root of the next iteration as the inflection point of . Mathematically,

which generalizes exactly as shown in equation .

## Formulations to Iterative Image Registration

There are several ways to adapt the equation for use with Newton’s method. Note that, due to the iterative nature of this method, we are always seeking to determine an incremental change to the parameters being optimized , which will bring us closer to the maximum of the image similarity function. The calculation of such incremental change to involves several extremely computationally expensive tasks, such as calculation of image gradients, Jacobian and Hessian of the transform function (evaluated at each pixel!), and so forth.

Therefore, we need to formulate our iterative scheme carefully to avoid as much calculations as possible. Below, I briefly introduce the most common ways to perform this task.

### Forward additive

The forward additive formulation is possibly the simplest approach, and combines the classical formulation of Newton’s method with the most basic Taylor series formulation, which approximates the function at the origin (that is, at ). The idea here is that, at the -th iteration, the origin of the similarity function is re-centered at :

Note that the warp function is now expressed as . Here, is the variable, and is a constant. Therefore, the Taylor series of the image similarity function expanded at will approximate it at .

At each iteration, we will find a that brings us closer to the desired maximum, and then we find .

By using this formulation, we usually end up having to calculate some very convoluted Jacobian and Hessian matrices for the transform function . The *Forward compositional* formulation was proposed to simplify this procedure a little bit.

### Forward compositional

The idea of the *forward compositional* formulation is to use function composition to describe how to incrementally modify in order to reach :

In order to be able to use this formulation, the image similarity function must be also reformulated:

The nice thing about this formulation is that when elaborating the first and second derivatives of the image similarity function (which are required for the Taylor series expansion, as described previously), you will eventually have to evaluate the Jacobian and Hessian matrices of at . There are two good things about this: The first is that the analytical derivation of these matrices can be greatly simplified. Secondly, at least part of these matrices can be precomputed before running the iterations of Newton’s method.

All things considered, the forward compositional formulation may make our job a little easier, but the computational complexity of the optimization algorithm remains essentially unchanged. Depending on how you model your optimization framework, you can drastically decrease the computational complexity by using the *Inverse compositional* approach.

### Inverse compositional

The problem with the previous formulations is that, when computing the first and second derivatives of with respect to , we usually end up with formulas that depend on . Since is updated at each iteration, we end up having to recompute all terms that depend on it as well.

One way to improve this situation is to modify the image similarity function so that the reference image is warped by , so depending on the similarity function, we end up being able to precompute a large amount of matrices:

This adaptation requires the update step to also be reconsidered. Since now describes a transform that brings closer to , we need to adjust the update step in order to find given and .

This can be done as follows. We know that applying to and to must be equivalent to applying to and to , that is,

To visualize this, compare the *before* and *after* a step of the Newton’s method. The point corresponds to the optimum of the parabola that passes through and can be reached via a step of . To determine how this step is applied, let’s replace by in the left side of equation :

Now compare the result of equation with the right side of equation and we see that the update step can now be written as:

### Further reading

I’ve only barely scratched the surface on the topic of formulations to the image registration problem. Each one of them have their own requirements in terms of what types of transform functions are supported. If these requirements are met, they are all proven to be equivalent. The curious reader is invited to read the paper *Lucas-Kanade 20 Years On: A Unifying Framework*, by S. Baker and I. Matthews.

At this point, some concepts evoked in that paper may still sound like black magic to the reader, especially those who have not studied the fields of real analysis. For now, the most important are the requirements for the transform :

- The forward compositional formulation requires the “
*set of warps to form a semigroup*“. This means that the composition of transforms must be associative – ; and they must obey the*closure*axiom, that is, the result of a composition of warps must also be a warp. Finally, although the paper doesn’t explicitly say so, there must also be the*identity*warp parameter with which the warp does not modify a point – that is, . - The inverse compositional formulation has all the requirements from the forward compositional formulation, as well as an additional requirement: The warp functions must also be invertible (and that inverse must also be a valid warp function). Obeying all these axioms is what makes it a
*group*.

## Final thoughts

This was the first post of a series about how to solve the image tracking problem via a non-linear optimization framework. In this post, I introduced the general idea of the iterative Newton’s method and briefly talked about how an arbitrary image similarity function can be adapted to be used with this framework. In the next post, I’ll dive into the details of one example, using the inverse compositional formulation combined with the Mutual Information similarity function.

It is clear that the Newton’s method is sensitive to the initial guess provided to it. Depending on the value provided to , there is always a risk of convergence to local maxima of the image similarity function. There are several ways to overcome these obstacles: For instance, one can use a robust estimator such as a keypoint based registration to determine . Furthermore, it is possible to perform the tracking algorithm in several scales of the input images, from the coarser to the finest, using the output of one scale as the input to the next scale. This has been shown in the literature to vastly improve both the convergence region as well as the convergence rate of the iterative algorithms.

Nevertheless, depending on how you model your solution, there are probably better methods than Newton’s out there, such as *Gauss-Newton* and *Levenberg-Marquardt*. The Lucas-Kanade modelling of the image registration problem has been shown to work much better using these algorithms.