Large Image Elastic Stack alignment via TrakEM2

Hello everyone,

I am trying to align a stack of 169 RGB images in total using the elastic alignment in TrakEM2. I aligned the images via the least squares method (firstly rigid, secondly affine). Afterwards, the pictures had a size of 13741x13696 pixels and roughly 500MB. In a third step I tried to use the elastic alignment but I cannot find any working parameters. Every time I tried the alignment it finished stating “Alignment done.” But the applied forces were straight 0.0 N. Are there any suggestions how to choose the parameters for this case? I am thankful for any suggestions!

1 Like

Hey @MaxAC,

It would be helpful if you posted example images, the parameters you tried, and the debug output that trakem2 produces.

One general tip for finding working parameters is to explore the Plugins > Feature Extraction Fiji plugins. These are the same methods that trakem2 uses to find correspondences between the images during elastic registration. If it’s matching that is causing problems, then using those plugins will help you iterate / experiment more quickly.

This page documents what the parameters of the SIFT point point matcher does.


Hi @bogovicj,

thank you for your reply. I chose the following parameters:
Block Matching:
layer scale: 0.25
search radius: 50
block radius: 75
resolution: 30
minimal PMCCr: 0.6
maximal curvature ratio: 10
maximal seond best r/best r: 0.9
local smoothness filter: yes
approximate local transformation: rigid
local region sigma: 150
maximal local displacement (absolute): 20
maximal local displacement (relative): 3
test maximally 7 layers
elastic transform: thin plate spline

SIFT parameters:
initial Gaussian blur: 1.6
steps per scale octave: 3
minimum image size: 64 px
maximum image size: 2048 px
feature descriptor size: 4
feature descriptor orientation bins: 8
closest/next closest ratio: 0.92
clear cache: yes
feature extraction threads: 60

Geometric filters:
max alignment error: 1500 px
minimal inlier ratio: 0.1
minimal number of inliers: 10
approximate transformation: affine
ignore constant background: no
tolerance: 5 px
give up after 3 failures

approximate transformation: rigid
maximal iterations: 1000
maximal plateauwidth: 200
stiffness: 0.1
maximal stretch: 2000px
maximal iterations: 1000
maximal plateauwidth: 200
use legacy optimizer: yes

The Logs can be found in the attatchment. (131.1 KB)

I will send you a download link for some example pictures via private message as I don’t feel comfortable posting them publicly.

Thank you very much in advance!

1 Like

HI @MaxAC,

Wow, I believe we have exactly the same problem with TrakEM2 elastic alignment. Have you found the solution?

In my case, I have a stack of ~50 images to align. I loaded them into TrakEM2, did the elastic align with tested parameters. And then the program ran but no matched blocks are found. In the end, I also get 0.0 N force and nothing is really done on my images.

However, directly using the elastic alignment plugin in Fiji works fine for me. My images didn’t become too large. Have you tested both elastic alignment and SIFT rigid alignment parameters through Fiji (it seems like you are using the default SIFT parameters)? One way to troubleshoot this can be doing the SIFT alignment separately before the elastic alignment to find out which one goes wrong.

@Chenghaz @MaxAC,

Sorry I just have not yet had time to look into this further.
I’ll follow up here when I learn something.


Hi @Chenghaz,
I did basically the same thin you did and it worked out for me as well. So I did the SIFT and the Elastic alignment seperately and did not use TrakEM2 for the Elastic Alignment.Thank you for the advice!

Hi @bogovicj,
thank you aswell! I used the Feature extraction Plugin to find the working parameters for me, which worked out really good!

Now, I would like to work with a larger amount of images, which means I need to use my universities computation cluster. Therefore it is necessary to create a script. However, the macro-recording did not work with the elastic alignment. Does anyone know if it is possible to create a script for elastic alignment?


Hi everyone.
I kond of figured out how to use the scripting. Though, I have a problem as the variable “resolution” is used twice (once in the “Output”-dialog and once in the “Block Matching Parameters”-dialog). I additionally get the notification saying “add an underscore to the corresponding label in the dialog to make the first word unique”. But I gaot the feeling just adding an underscore in the script would not help as there is no “space” that I could replace with it. Here is the code:

run("Elastic Stack Alignment", elastically=M:/test/ interpolate visualize resolution=128 scale=1 search_radius=150 block_radius=200 resolution=30 minimal_pmcc_r=0.1 maximal_curvature_ratio=1000 maximal_second_best_r/best_r=1 use_local_smoothness_filter approximate_local_transformation=Rigid local_region_sigma=200 maximal_local_displacement=60 maximal_local_displacement_0=3 series_is_aligned test_maximally=5");)

Any suggestions?