Intersection coordinates of two ROIs

I’ve two overlapping ROIs and I want to the coordinates of points of their intersection. I will be using those coordinates to draw a single line between the two coordinates.

My problem would be like this:

I want to detect coordiantes of red dots. Two shapes are outline of two different ROIs.

Detailed/Real Problem:
I’ve ROIs that are supposed to represent cell boundaries. Due to some reasons during the analysis, I get overlapping cell portions. I’m trying to rectify this error by removing the overlapping portions while still keeping each cell boundaries continuous.

I’ve marked overlapping cell portions in red. Each shape is an outilne of a ROI representing a cell.

You could try Analyze Skeleton to find the intersection/branch points. The SkeletonResult class has methods that output arrays or lists of junction points.

Or, naively, if you have found all pairs of ROIs that overlap/intersect, and have obtained their outlines, as I gather from your question, couldn’t you for each pair, ROI_i and ROI_j, just iterate over all points on the outline of ROI_i and check if each point belongs to the outline of ROI_j as well. If this thing is well behaved you’ll get two such points for each pair of ROIs.

1 Like

Hi Siddarth,

So do you want the points of the intersecting lines, or the overlapping area?

@Sverre Former one. Points of intersecting lines.

What you want cannot be done from the 2nd image you provided. Next to the two lowest orange regions there is one region that would appear to be background, but it is not possible to know if it is an overlap or just another tangential region. The current representation seems ambiguous.
Another one such region is between the two lowest regions, is that bit in the middle background or overlap?
Even if you could identify the overlap from the background (let’s say that the overlap is a different grey intensity than the background) there is no guarantee that the intersection is a point: two equal sized squared regions overlapping horizontally side by side could have no intersection points (the overlap would be a rectangular area).
Something I noted is that when those intersection points exist, like in your 1st image, those points are neighbours to 4 different types of pixels: region 1, region 2, the overlap and the background. Maybe you can use that to identify them, but obviously you need a labelled image for that.

If you could identify all your regions separately you could use region connection calculus to find the “partial overlap” (PO) regions in your set of regions using a multiple comparison of regions relations (that is every region vs every other region) with the RCC5D logic.

Please see:
and some principles and code here:

However I do not know how you capture your data, maybe the regions are already overlapping and you cannot work out if a pixel belongs to a region or an overlap. In that case RCC will not help.


Good day Siddharth Yadav,

even in the case of only two overlapping ROIs (your first figure) the determination of the intersection points will be rather costly, at least if you try to compare the coordinates of both ROIs. The reason is that the coordinates returned by

Roi.getCoordinates( x, y );

may not contain the intersections points but only points nearby. I.e. you have to compare the array values with tolerance.

If you have more than two ROIs (your second figure) things become much more involved because first you must determine which ROIs overlap each other. Although this is possible, you may need to perform a great number of tests.



1 Like