How to apply slice alignment coordinates of one stack to another?

Hi all,

I have a two-channel timelapse dataset depicting a single unidirectionally growing cell.
The data is arranged in two separate stacks (transmission and fluorescence).
I would like to align all slices in the fluorescence stack, but can’t use classical registration/template matching tools due to the lack of clear recurrent features in the fluorescence images.

To solve this, I’m using template matching to align all slices in the transmission image stack, and extract the new X/Y coordinates for each slice.
I would now like to apply those coordinates to the fluorescence stack.
However, until now I haven’t found a way to do this.

So my questions is: How to apply slice alignment coordinates of one stack to another?
Any great ideas?:slight_smile:

Thanks!

Sébastjen

Hi @SSchoenaers,

Welcome to the forum.

This is relatively easy to script with ImageJ(2), and I’m happy to help you get going. A question though - how are you storing the new x/y coordinates for each slice?

John

Hi John,

Fantastic, thanks! Very curious to see how you’d solve this (I’m not familiar with scripting in ImageJ).

The ‘Template matching’ Fiji plugin generates a results table depicting the x/y displacement of each slice relative to slice 1.
This data is then exported as an excel file.
I include a .zip file in this post with:
(1) the original stack
(2) the aligned stack
(3) the excel table resulting from the alignment of the transmission stack

example.zip (5.8 MB)

Please do let me know if you need any additional info.

Sébastjen

Hi John,

Did you get the chance to have a look at this?

Thanks!

Sébastjen

Hi,

Perhaps you can do this easily with macros.
So, I am also waiting John’s answer, but I would like to introduce my plugin “CoordinateShift
This plugin can not only align the image but also apply the shift value from tab separated text.
First, please use my shift method in fluorescent image.
If it dose not work well, please convert your shifted value data to tab separated text.
For example:
1[TAB]X1_value[TAB]Y1_value[RETURN]
2[TAB]X2_value[TAB]Y2_value[RETURN]
.
.
.
n[TAB]Xn_value[TAB]Yn_value

And then, copy the all values in the clipboard.(command+c or control+c)

Open your image in ImageJ, and start my plugin.
Then, right click on the table in my plugin.
And select past the value from clipboard.
Then, click apply button. *Reflected on all channels and all z slices
Please try it.

hwada

Hi Hwada,

It’s been a while, but I’m picking up this topic once again.
I’ve tried your plugin and it has some fantastically usefull features.
There are however two things that are still preventing me from solving my issue:

  1. I am unable to copy paste the ‘shifted value data’ originating from the ‘template matching’ plugin into the CoordinateShift table.
    More specifically, when I right click on the table I immediatelly get the following error message:
    Exception in thread “AWT-EventQueue-0” java.lang.ArrayIndexOutOfBoundsException

Is there any way that you can comment on how this can be solved?

  1. Being able to use the Shift function that is part of your plugin would simply solve everything, since you can use e.g. channel 1 as a template, and it will apply those values to alle channels in the hyperstack. the ‘Template matching’ plugin is unable to do that, since it only works on single channel stacks.
    However, the algorithm behind your Shift function isn’t quite as precise as the one that’s running the ‘template matching’ plugin. Unfortunately, that means I can’t use it on my data specifically.
    This is maybe a far stretch but is there an easy way to e.g. link the ‘template matching-align slices in stack’ plugin to your shift function in a way that it could be applied on a hyperstack?

Thanks Hwada for the help until now!

Sébastjen

Hi, @SSchoenaers

Thank you for using it. I also appreciate any bug reports.
Regarding 1., I think that the problem mentioned is solved in the latest version, so if you are using the old one, try changing to the new one.
Also, it seems that the data copied in Excel does not read anything well. Please try using the data once copied to a text editor.
However, the shift data created from template-matching does not have information on the first slice (since it does not shift), and Coordinate shift requires it, So right click on n=2 and try past.

Template-matching

Slice dX dY
2 -0.214575 0.0380251
3 -0.6280313 -0.1832602
4 -1.1604622 -0.142509

CoordinateShift

n x y
1 0 0
2 -0.214575 0.0380251
3 -0.6280313 -0.1832602

With regard to 2, it may be possible to parse and import it if there is source code etc., but I think that permission to the developer is also
* Simply get the (x, y) coordinates to shift and reflect them in the CoordinateShift table.

If you still can’t solve it, please contact me.

hwada

Hi @Hwada,

I tried to remove and install the plugin again, just to make sure I’m using the latest version.
Unfortunately I keep getting the error I mentioned earlier.
When I simply right-click on the coordinate table (just clicking, nothing else), this is what appears:

Might this be happening because I’m using java version 8?

Hi, @SSchoenaers

I’ve found this to happen if I don’t select a row in the table.
This is because the selection will be canceled immediately after starting or immediately after pressing the Clear_All button.
I will fix this problem, but for now, I think it will work if you left-click some row and select it, then right-click.
Another problem was found with this. In this case, it can skip the 0 value of n=1 by pasting with n=2 selected, but for some reason I found that the last row does not reflect the value … I plan to fix this as well.
I will inform you after the fix.

hwada

Hi @hwada,

When selecting a row, the error message indeed no longer appears.
Now I encountered a second problem.
There is no dialog window appearing when right clicking on the selected row which prevents me from copy pasting from clipboard.
I also tried simply right click-ctrl v, but nothing happens.
So it seems like there’s no way for me to copy paste my coordinates in the table.
Any idea on why that would be happening?
Thanks again for your help, strongly appreciated!

Unfortunately, I can not confirm the phenomenon, but could you tell me the OS and the versions of Fiji and Imagej? Actually, I’m adding template matching using opencv and javacv, but it came to a point where it works in the development environment. However, I found that it did not work if I put it in the production FIji or Imagej, so I am now looking for this cause. I’m going to ask a few questions on this forum so I think it will progress if I can get some advice.

Hi, @SSchoenaers ,

I uploaded the new version of CoordinateShift on our website.(ver. 20200731)
Please download and try it.
However, it does not work well with Fiji, so please try with ImageJ.
Also, JavaCV is required, so please download the binary from the following and install it in the plugin folder.

How to use:
open the image
start this plugin
check “Comparison is the first slice”
select “Template Matching” at the method combo-box
select a part of Image by ROI
Then, click the shift button

Known defects:
When “Comparison is the first slice” is checked, processing stops except t=1

hwada

I understood the reason why it does not work with fiji.
It seems that it is simply due to the different version of javacv.
I am using the latest 1.53 in the development environment, but it seems that 1.42 is downloaded to fiji.
I certainly remember a big change around here.
If you want to run it on fiji, please contact me and I will respond.

hwada