# Machine Vision

cancel
Showing results forÂ
Did you mean:Â

Solved!
Go to solution

## How can i detect overlapping ROIs?

Good day,
in my application i set a certain number of ROIs in specific regions defined programmatically. Unfortunately they could overlap each other. Since that the ROIs that i set are regions of analysis overlapping two ROIs means analyze the same region two time. So i need to delete one of the two overlapping ROIs. I can't figure out how i can detect the overlapping ROIs. Note that the ROIs may not completely overlap but they could overlap each other only in undefined percentage.

Francesco

Message 1 of 4
(3,882 Views)

## Re: How can i detect overlapping ROIs?

What shape are the ROIs?  Rectangles would be fairly easy to check for overlap, but random shapes would be more difficult.

You could check rectangles by generating a list of left, right, top, bottom coordinates.  For each rectangle, check if its left or right is between any other left/right pairs AND top or bottom is between the top/bottom of the same ROI.

For random shapes, I might consider converting each ROI to a mask, then adding all the masks together.  If any pixels have a value greater than 1, you have overlap.  You would have to use each mask to figure out which one it is.

Bruce

Bruce Ammons
Ammons Engineering
Message 2 of 4
(3,877 Views)
Solution
Accepted by topic author FM82

## Re: How can i detect overlapping ROIs?

What shape are the ROIs?  Rectangles would be fairly easy to check for overlap, but random shapes would be more difficult.

You could check rectangles by generating a list of left, right, top, bottom coordinates.  For each rectangle, check if its left or right is between any other left/right pairs AND top or bottom is between the top/bottom of the same ROI.

For random shapes, I might consider converting each ROI to a mask, then adding all the masks together.  If any pixels have a value greater than 1, you have overlap.  You would have to use each mask to figure out which one it is.

Bruce

Bruce Ammons
Ammons Engineering
Message 3 of 4
(3,876 Views)