Apply transform computed in TrakEM2 to other channels

Hello

I have some multi-channel dataset (from an Array Tomography application) and I would like to align the “tiles” (2D images) from each layer (Z position, made from multiple overlapping tiles) into a 3D (single stack). I have managed to get the job done for a single spectral channel and would like to apply the computed transform to the other channels. Manually editing the .XML file didn’t work as additional files are generated by TrakEM when saving a project. Any suggestions here? Maybe one can create a template?

Help much appreciated!
Pablo

1 Like

Any idea came to mind? I am hitting a wall here so every piece of help will be much appreciated.

Hi @pbl007,

Sorry for missing this.

How big is your xml? I.e. would it be unreasonable for you to post it somewhere (just the xml, not images)? Looking at it might help in coming up with a solution.

John

Hi John,
thanks for picking this up. We got a hint to actually leave the xml file and write a macro to copy the computed transform for each patch to create a new layer/layers with the additional channels. We will give it a try and post the working macro here (once we get it to do the trick). A bit of a journey into the inner workings of TrackEM2.

1 Like

Hi Pablo,

sorry I didn’t see this earlier. An example that could work for you (I know you have it already, this is for general documentation purposes) is here below:

from ini.trakem2.display import Display, Patch
for layer in Display.getFront().getLayerSet().getLayers():
  for patch in layer.getDisplayables(Patch): # expecting only one
    affine = patch.getAffineTransform().clone()
    filepath = patch.getOriginalFilePath()
    filepath = ... # MODIFY to point to the second, third, etc channels
    new_patch = Patch.createPatch(patch.getProject(), filepath)
    new_patch.setAffineTransform(affine)
    layer.add(new_patch)
  layer.recreateBuckets() # internals of Layer for finding images etc.
Display.repaint()

There are a number of related examples in the TrakEM2 Scripting Tutorial.

Hope this gets you started.

Albert

1 Like

Thanks again Albert!

Minor modification to the posted code to get this going. The scrip below “swaps” the channels; can one add multiple images to the same patch object to make this into a multi-spectral display?
Thanks again Albert for pointing me in the right direction!

from ini.trakem2.display import Display, Patch
import string
​
​
for layer in Display.getFront().getLayerSet().getLayers():
  for patch in layer.getDisplayables(Patch): # expecting only one
    affine = patch.getAffineTransform().clone()
    filepath = patch.getCurrentPath()
    print filepath
    new_filepath = string.replace(filepath, "Ch02", "Ch01",1)
    print new_filepath
    new_patch = Patch.createPatch(patch.getProject(), new_filepath)
    new_patch.setAffineTransform(affine)
    layer.add(new_patch)
  layer.recreateBuckets() # internals of Layer for finding images etc.
Display.repaint()
1 Like