Note
Go to the end to download the full example code.
Coregistration options in mdreg#
By default, mdreg
performs coregistration using the optical flow method
optical_flow_tvl1()
as implemented in skimage, with default
settings for all parameters.
The coregistration can be modified either by overriding these defaults, or by coregistering with one of the optional coregistration engines wrapped in mdreg: ants and elastix.
This example shows how these options can be customized to achieve the best results.
Setup#
import numpy as np
import mdreg
Load test data
Coregistration with skimage
#
If we don’t provide any detail on the coregistration method, mdreg
uses the optical flow method optical_flow_tvl1()
from the
package skimage
for coregistration:
Visualise the results
This has clearly had some effect, but the motion correction is not perfect and the coregistered image is somewhat blurred. We could try to improve the result by optimizing the parameters.
One parameter in
optical_flow_tvl1()
is the attachment, which by default is
set to 15, but can be set to smaller values for smoother results. In this
case we want the opposite, so let’s see what happens when we set it to
30.
We can do this by providing the fit_coreg argument to mdreg.fit:
This appears to have had the desired effect and has resulted in a better motion correction.
Coregistration with elastix#
An other approach to optimization is to use another coregistration engine.
mdreg
also wraps elastix, so let’s try that.
By default mdreg
applies elastix
with bspline deformations, and default settings for all
parameters. The result can be further customized by providing any valid
elastix
parameter in the dictionary. For this example we will change the
default grid spacing from 16mm to 50mm. Since elastix is not default, we
need to provide the package name as well. It also needs the pixel spacing
so that dimensions in mm are well defined:
Coregistration with ants#
Apart from skimage
and elastix
, mdreg also wraps ants
as a
registration engine.
It can be called like elastix, by specifying the package and, if needed, any of the parameters to be set to different values than the default. We illustrate this here by coregistering with a transform type different from the default:
invalid value encountered in cast
Looking at the results, this is not a great solution for these data.
Total running time of the script: (55 minutes 9.884 seconds)