Automating fiducial-based image registration using BigWarp

Hey everyone,

first of all I am new to the field of automated image analysis and this community, so please excuse my limited expertise and “dumb” questions arising from this.

Those of you who I have been lucky enough to meet in Bordeaux have probably already heard of my current project. For those of you who have not I would like to give a quick summary:

I have a bunch of super-resolved images coming from consecutive imaging rounds each containing an individual set of proteins that need to be registered onto each other for correlation analyses. To aid this registration I am simultaneously imaging a set of fiducials in a separate color channel. Sadly (presumably because of non-chromatic aberrations) I can not use a simple rigid transformation to correct for the ROI displacement between imaging rounds. During the Bordeaux training school @christian_tischer therefore suggested to use BigWarp instead and it works like a charm as long as I do the registration manually. The obvious next step now is to automate that process for high-throughput analysis and that is where I am stuck at the moment.

My actual problem goes as follows:
I already managed the easy task of automatically extracting the fiducial coordinates from the respective images and saving them as .csv files. However I now need a way to combine those coordinate tables from the target and the moving image into one file to feed it into BigWarp or come up with a way to already acquire that table containing the coordinate pairs in the right format.
To add to that problem I also need to make sure that each pair of coordinates really originates from the same fiducial which could be done by only allowing pairs to be matched within a certain radius around the target fiducial, but again I have not found a way to do that so far.

Since I am using the current home-office situation to improve my coding skills I am happy to figure out the actual macro myself as far as I can (of course I am open for suggestions nevertheless), but I definitely need help coming up with a strategy to solve my problems from above.

So thanks in advance for any suggestions and stay safe (at home)!

P.S.: if you need any additional information or example images, I am happy to provide it.

2 Likes

Hi @Smillo,

Welcome to the forum, and glad Bigwarp has been working for you so far.

What you describe is something I’ve wanted to add to Bigwarp for awhile.

It should be easy to code up something that does what you need once I find a little time.
That is, I can make a script that takes two csv’s and imports those points along with the images into BigWarp. As well, it will also not be hard to make something that transforms the images in the way they would be transformed were the landmarks to be pulled into Bigwarp.

Sounds like you’re in good shape then. I’ll code up something preliminary for you, and then we can discuss more.

John

P.s. Thanks @Christian_Tischer for the recommendation :smile:

2 Likes

Thank you very much @bogovicj for offering your help! I am looking forward to your suggestions.

1 Like

Hi @Smillo,

I wrote a quick script to do part of what you need.

It takes two csvs - one for moving and one for target points, and creates a bigwarp landmark csv file.

John

p.s. Read more about scripting in fiji here.

1 Like

Hi @bogovicj,

Thanks a lot for your script and please excuse my late answer.

I have had an in-depth look into your code by now and hopefully understand the basic operations it does. Unfortunately though I have not been able to get your script to run so far.

My first question therefore is whether it would be possible to translate your groovy script into ImageJ Macro? Since that is the only language I have relevant experiences with discussing and implementing your script would be a lot easier for me then.
My second question relates directly to your code. If I understand it correctly your line 21 - 27 splits the csv files into 64bit numeric arrays and line 29 - 37 checks whether both resulting arrays are identical in column number? The variables assigned to both input files however are only used in line 41/42 the first time which to me means the lines 21 - 37 do not have any input?

Thanks again for your help and looking forward to your answer!
Steffen

Hi @Smillo,

It may be possible to turn this into a macro, but not easy. I personally don’t have the time or expertise to do it myself. But do have the time and expertise to help you understand / edit the script I attached.

To answer your particular questions:

Yes, with one small clarification: that code works on one row / line of the csv at a time.

That’s the right way to think about it, yes.

lines 21-37 define two functions: a parse function, and a check function. So they don’t need any inputs at the “time” they’re defined. Those functions can be called on any inputs defined at any time.

Hope that helps, and keep the questions coming if you have them,
John

Hi @bogovicj,

it took me a little longer than I had hoped, but I have finished the first half of my project now which is the macro script to automatically extract fiducial coordinates and translate them into a .csv file readable by BigWarp. There are still some aspects of the script that need further optimization, but once that is done I am of course happy to share it.

For the second part however I do need some help again as I realized that at the moment it is possible to open BigWarp from a macro but impossible to import the .csv and export the transformed image from it (guess I should have checked that before…). For a completely automated workflow obviously this is necessary though, therefore I would like to know whether you are still working on BigWarp and could include this functionality with the next release?

Thanks a lot,
Steffen

1 Like

Hi @Smillo,

Glad to hear!

I am and will try to make this possible

John

Hi @bogovicj,

I just wanted to kindly ask, whether there has been any progress at making BigWarp macro-recordable?

Best,
Steffen

2 Likes

Hi Steffen (@Smillo ),

Thanks for being patient with me. I hope I’m not misunderstanding again, but is this right?

You need something to use an ImageJ macro to transform images with landmarks a given csv, and a given moving image.

If so, something close to this is possible with the Big Warp Apply plugin. It takes files as input:

  1. a moving image file
  2. a landmarks (csv) file
  3. (optionally) a target image file

and transforms the moving image and writes it to a file. The down side is it’s very file-centric.
But it is macro-recordable (see below)!

If it would be better / more convenience for you for it to work on images that are open, I can make that change pretty quickly (in the next couple of days).

It’s been awhile, and I apologize for that, but I have some time now (finally) and want to make this better.
Thanks again for your feedback and patience,

John

This is a macro I recorded:

run("Big Warp Apply", "landmarks_image_file=/home/john/tmp/mr_test_landmarks.csv moving_image_file=/home/john/tmp/mri-stack.tif target_space_file=/home/john/tmp/mri-stack.tif resolution=Target field=Target point=[] x=1.0000 y=1.0000 z=1.0000 x_0=0.0000 y_0=0.0000 z_0=0.0000 x_1=-1 y_1=-1 z_1=-1 interpolation=Linear threads=4");

Hi John,

actually I have already tried to use BigWarp Apply back in the days, but always got a console error instead of a recording and therefore assumed the plugin wasn’t working properly. Since those attempts were done on a different computer unfortunately I can’t reproduce the exact error anymore, but from quick testing I just figured the problem might in fact have been different styles of file separators?

Anyway, I was able to integrate your recording into my macro now and everything runs smoothly, so thanks a lot for your help!

Since I’m using batch mode I don’t necessarily need that functionality but I guess it would make the macro more user-friendly / intuitive to other people and therefore be a great addition. With my experiences in mind I’d also suggest to add conventional error messages (e.g. “File not found or path does not exist”) instead of redirecting potential errors to the console, which would make debugging a lot easier for users not familiar with Java language (like me :see_no_evil: ).

In the meantime I will continue testing of my workflow and get back to this discussion once results are reliable or I’m stuck again.

Cheers,
Steffen

1 Like

Hi Steffen @Smillo

Great news! and thanks for the suggestions - I’ll keep those in mind.

Please do keep me posted if any issues come up again,
John