Merge two labeled images

Hello everyone,

I have two labeled images:

  1. an image that contains labeled cells.
  2. the same image that contains labeled junctions (the line that connects two connected cells).

My task is to find, for each junction the two cells that it connects. I used Region Adjacency Graph and it works great. the problem is that this tool gives me pairs of cells that are connected without telling me which junction is connecting them.

What I thought about is to dilate the junctions image, then merge the two images, and find for each junction, what are the most two occurrences of labels from the cell image that appears in that junction.

The problem is that I don’t know how to implement that (maybe there is a plugin for this that I don’t know). Do you have any suggestion on how to do this?
If there is another idea for implementing this, this will help a lot also.

Thanks.

Can you post an example with both those images?

Thanks for the reply. I can’t upload the full images, but I will upload part of them to show what I am talking about:

  1. This is the labeled cells image. In this screenshot I was pointing the mouse on cell number 1012.
    cells

  2. This is the labeled junctions image. In this screenshot I was pointing the mouse on junction number 927.
    junctions

The labelled junctions image do not seem to be correct. There are some places where the junction has been discontinued.
Also there is only 1 junction in your 2nd image: it is a single connected component.
From the top image alone, you should be able to know which neighbours each cell has using morphological operations.
First, get all the XStart YStart coordinates of the cells withe the Particle Analyzer, then label the connected components, so each cell has a unique colour/label. Since now you know which cell has which colour (check the image colour at the XStart YStart pixel), do a binary reconstruction of each cell using the XStart, YStart pixel as the seed. That produces only a given cell shown in the reconstructed image. Dilate it twice. The dilated region will now overlap with the neighbours, so if you investigate which colours exist in the intersection (e.g. AND) of the dilated image and the labelled image, you know which cells are the neighbours. Then repeat the same for all the other cells.
It sounds complicated but it is doable with a macro.

Alternatively you could use region connection calculus (RCC)
https://blog.bham.ac.uk/intellimic/spatial-reasoning-with-imagej-using-the-region-connection-calculus/
You want the NC (neighbour connection) relation between objects in that image.
We developed a new (very) fast algorithm to do that:

Landini G, Galton A, Randell D, Fouad S. Novel applications of Discrete Mereotopology to Mathematical Morphology. Signal Processing: Image Communication 76:109-117, 2019. PDF

I will release the fast algorithm plugin very soon but if you are in a hurry and are willing to wait in front of the screen, the old plugin in that page can do it… although slowly.
Hope this helps.

1 Like

Thank you very much for the help.
I am not that much familiar with Fiji/ImageJ, so the first approach is too complicated for me.
I also tried the second approach, but after installing your plugin, i get a lot of Java exceptions…

Anyway, the discontinued junction will not make the results to be wrong, so we can ignore it.

Probably you did not include the plugins mentioned in the Requirements section in that page.