Computes the elastic barycenter of an array of images.
Uncomment the wanted example of the file toy_barycenter.py
and run it using.
python toy_barycenter.py
If you are connecting with ssh
, remember to connect with -X
or -Y
to visualize the transformations.
You can find other useful image reading functions in image_functions.py
in case the amount of images you want to compute a barycenter for are more complex.
Make sure that you update the variable outpath
in toy_barycenter.py
to describe where you want to save the final barycenter array.
Find more comments written in the code.
Let
In order to find
A gradient descent algorithm (in this case ADAM), will try to minimize this loss so that the source gets registered to the target image. The algorithm will quantify the number of folds in the registration by taking the determinant of the Jacobian. Ideally, we want there to be no folds in the registration. For more information about elastic registration, you can refer to Chapter 9 of Modersitzki's book "Numerical Methods for Image Registration".
Given images
The following is the algorithm used to compute the elastic barycenter of images, as illustrated by the equal radius circles distributed along the diagonals example in toy_barycenter.py
.
First, initialize the images that you want to compute a barycenter for:
For every single image, we want to find a function
In order to compute the barycenter, we need two updating loops:
- One external loop that updates the barycenter
$I_b$ based on the registered images$I_i(\phi^{-1}_i(y))$ - An internal loop that registers via gradient descent every image
$I_i(x)$ to$I_b$
When we start the external loop, we want the barycenter to be computed via an unweighted average of the images' intensities. That is
Before any registration from
After the update of the barycenter, we register every image to the barycenter via the inner loop:
The following is the progress of the registration from
NOTE: the inner registration images are only visible by setting the parameter
verbose=True
intoy_barycenter.py
After approximately 10 epochs in the external loop, the barycenter will converge:
At the end of the gradient descent optimization, we will be able to see the registration grid for every image
Similarly, we'll be able to see the individual loss and the total loss of our registration algorithm. The loss will display a peaking pattern every time the barycenter was updated and will break apart the loss to its similarity and regularizing terms: