Finetuning automatic image alignment in QuPath

Hi everybody,

I am trying to compare IHC staining patterns of 4 different biomarkers on whole mount slices containing tumor and non-tumor tissue. At the moment, I am working on automatically aligning the 4 consecutive sections for each slice.

I am working with this script by @smcardle and @Mike_Nelson (thank you for your work!) to rigidly align the images:

Which uses these alignment functions:

autoAlign(serverBase,serverOverlay,registrationType,affine,20) autoAlign(serverBase,serverOverlay,registrationType,affine,10) autoAlign(serverBase,serverOverlay,registrationType,affine,5)

(side note: what does the last input variable (20, 10, 5) mean here?)

The script works fine, but the results of the automatic image alignment are not that great, probably due to internal deformation within the tissue. I find that the manual alignment, in which you can roughly pre-align the images, gives a better result.

Does anyone have any tips on how to improve the alignment? Is there for example a way to focus the alignment on a specific part of the image? I am mainly interested in the tumor, so as long as that part of the image is aligned, it doesn’t matter too much if the surrounding tissue is not.

Or is it maybe possible to half-automate the process, in which I can still provide the manual pre-alignment as input?

Any tips are greatly appreciated!

Kind regards,
Hilde

That gives the levels of resolution for each stage of alignment. The script does a coarse alignment first (20um pixel size), then 10 um, then 5 um. Alignment with larger pixel sizes will go faster and will be less sensitive to changes in images. If you start with two tissues that are very far apart and then try to do a fine alignment first, it will often fail to converge at all.

If you are having better luck with manual alignment than with the automated, then I would suggest trying to increase the pixel size of the first alignment step. Maybe try to do 50, 20, 10, 5?

You also mentioned that you are doing rigid alignment. Is there a reason for that? I find that affine works better in most cases, but particularly for sequential slices that you don’t expect to line up perfectly.

You can absolutely do a prealignment step manually. In the script, just before the series of autoAlign calls, there’s a line that says: Affine affine=[] . Do the manual alignment however you like to do it, then copy-paste the results into that bracket. It will use that as the starting condition. Maybe then instead of redoing all the levels of resolution, just go for a fine registration?

Further down in that post, I posted another version of the script that allows for annotation-based alignment. With this, you could annotate your tumors in all of your slides and just align based on those outlines. It might help if your extraneous tissue is very different slide-to-slide.

Also, this method for elastic registration was just posted this morning. I haven’t gotten to test it yet, but it looks fantastic! Cell-level accuracy on a whole slide image!

3 Likes

Hi Sara,

Thank you for your response and your suggestions! I will try them all out to see how to best optimize the alignment.

We chose for a rigid transformation, because the slides are all scanned on the same scanner and resolution, and we didn’t want to deform the cell geometry. However, when it improves the registration substantially, the tradeoff might indeed be worth it. Especially that last method with elastic registration looks great.

2 Likes