Obtaining transform from image alignment

Hi everyone,

First of all, congratulation to the developer for this great work. I’m just beginning to work with histopathological images and I’ve tested a couple of frameworks. In my opinion, QuPath is nowadays the best option to work with large images.

During my training in this software, I’ve been working with series of TMA images. Therefore, first of all, I needed to align the cores of two different images (easy, using Interactive Image Alignment). Later, I shared a tissue segmentation using the script exposed in Interactive image alignment (copying and pasting the transform matrix) and I found that the segmentation does not fit as well as it should. However, the aligned images were in the right position.

After trying a couple of things, I modified the InteractiveAlignmentPane class (lines 399 and 400) in order to obtain the transformation matrix with a better approximation. I mean, instead of obtaining three decimal places in the Transformation matrix, now it prints 6 values. For instance, Transform: [1.000 , -0.021, -638.914; 0.021, 1.000, 1136.988], now is shown as Transform: [ 0.999769, -0.021492, -638.913773; 0.021492, 0.999769, 1136.988041]. Then, the tissue segmentation fits perfectly.

Thus, now I would like to perform automatically the annotation (i.e. tissue segmentation) alignment, in order to avoid the lose of information, using a script but, to my understand (I’m not used to work with Java), all the methods in this class are privates and they are not accessible from the terminal, or using a script. So, I want to modified the class.

First of all, am I wrong? Is possible to obtain the transform matrix using a script? If it is no possible, which variable stores this information?


Hi @erme thanks for your kind words :slight_smile:

You could try this script:

import qupath.lib.gui.align.ImageServerOverlay

def overlay = getCurrentViewer().getCustomOverlayLayers().find {it instanceof ImageServerOverlay}
print overlay.getAffine()

The result is a JavaFX Affine object, which you can also interactively manipulate (although you might need to take care to be on the JavaFX application thread if you do).

I can’t guarantee the script will continue to work exactly as it is… the interactive alignment is at an early stage and I haven’t found time to turn it into something more useful. But I’m glad it already can be used, and it’s helpful for me to understand how and know it is worth keeping!

1 Like

Hi @petebankhead,

Thank you so much, your code works perfectly!

1 Like

Interesting note about the decimal places!