TrakEM2 Elastic Alignment Question



Hi all,

I’m trying to do the elastic alignment on my images through the TrakEM2 but it doesn’t work. Here is what I did:

      .1 The images were rigid aligned and cropped,  and that part works fine. 

      .2 The aligned images were loaded into TrakEM2. Each layer contains 4 patches from different channels. Then I used 

          'task = AlignLayersTask.alignLayersTask(layerset.getLayers().get(0))' 

           to do the elastic alignment. Actually, to figure out whether the error is because something goes wrong in my script, I also tried to load the images to TrakEM2, right click on the canvas, and use the "align" tool manually, it gives me the same log message and doesn't work either. 

      .3 A GUI window comes out and asks me for proper parameters. I selected "elastic alignment" and parameters which had already been tested by "Test block ..." plugin in Fiji. The elastic alignment runs. and in the log window, it reports no candidates passed the filter. The output images look same as the inputs. 

I also tried to do the elastic alignment without TrakEM2 (using Fiji-plugin-registration-elastic alignment) and it works fine. Hundreds of blocks are detected and pass the filter. So I totally have no idea why TrakEM2 can’t do the alignment. Does anybody know why? Or where can I find documentation explaining how to use the “align” tool in TrakEM2 in details? I read the User Manual of TrakEM2 ( and it seems like it’s just as easy as “click it and select parameters”…


Hi @Chenghaz,

Welcome to the forum.

You can find some documentation for the elastic alignment here.

It will be easier to help if you provide some more details. For instance:

  1. How many slices / layers in your image?
  2. How did you import your images into trakem2?
  3. How were the different channels arranged in each layer?
  4. Is this the fiji plugin you ran and worked for you? Plugins > Registration > Elastic > Elastic Stack Alignment
  5. What stack did you use as input to that plugin and how does that stack relate to what you imported into trakem2. e.g. did it have all 4 channels?

Posting screenshots will help. Posting the log output will probably be helpful too.



Hi John,

Thank you for the reply! Here are some details of what I did for testing:

  1. Just for test, I had 3 layers and each layers only contain one patch: I first opened them in Fiji, and made them a stack. And then I opened a new blank template of TrakEM2, right clicked on the canvas, and loaded the stack. They look like:

  2. Then I right clicked on the images - Align - Align Layers. And I selected “elastic alignment” and everything else I need.

  3. Then the alignment ran. It reported no candidates passed the filter.

If I use plugin- registration - elastic - elastic stack alignment on the same images stack (only one channel), it works fine. Here is the result of “Test block matching Parameters” with the same set of parameters:

For my real experimental data set, there are 4 channels. and they are loaded into one layer as 4 different patches. The patches are not linked and all visible. I firstly used a python script to load images and do the alignment. Here is the script (actually after the test, I think this may doesn’t matter since alignment failed with just only one channel loaded…)

Num_sections and filenames have already been defined.

Create a TrakEM2 project

project = Project.newFSProject(“blank”, None, out_folder)
loader = project.getLoader()
loader.setMipMapsRegeneration(True) # disable mipmaps
layerset = project.getRootLayerSet()

Create layers

for i in range(num_sections):
layerset.getLayer(i, 1, True)

Load images.

for i,layer in enumerate(layerset.getLayers()):
filepath = os.path.join(Image_folder, filenames[i])
patch = Patch.createPatch(project, filepath)
layer.add(patch, False)

filepath = os.path.join(Image_folder2, filenames2[i])
patch = Patch.createPatch(project, filepath)
layer.add(patch, False)

filepath = os.path.join(Image_folder3, filenames1[i])
patch = Patch.createPatch(project, filepath)
layer.add(patch, False)

filepath = os.path.join(Image_folder4, filenames3[i])
patch = Patch.createPatch(project, filepath)
layer.add(patch, False)


Run the alignment

from mpicbg.trakem2.align import Align, AlignTask, AlignLayersTask
task = AlignLayersTask.alignLayersTask(layerset.getLayers().get(0)) #elastic alignment