How to compare bounding box coordinates?

7 views (last 30 days)
Muffin
Muffin on 2 Nov 2012
Answered: Stalin Sabu Thomas on 20 Oct 2018
I have a number of bounding boxes for one greyimage, with one box for each connected component in the image. I need to figure out whichever boxes do not overlap with the rest and remove those pixels from the image.
For that, I want to be able to compare if there are overlaps between the bounding boxes, by comparing the corner coordinates or by using any function that can figure out any bit of overlap with other bounding boxes. After that, I need to set all the pixels in the boxes that do not overlap with any other to be black.
I need help with comparing and keeping track of the boxes and finally making the changes to the original image, before cropping into connected components.
Thank you very much in advance for your help! Any bit of help is very much appreciated! (:

Answers (3)

Image Analyst
Image Analyst on 2 Nov 2012
Tell me what the next step is, because I don't see why this strange thing would be necessary. I have never done that and I analyze regions all the time. Tell me what you really want to do and I'll tell you how to do it and most likely erasing blobs with non-overlapping bounding boxes won't be necessary. Upload your image to assist in your description.

Matt J
Matt J on 2 Nov 2012
One method would be to use VERT2LCON and LCON2VERT
Suppose that V1 contains the vertices of box 1 and V2 contains the vertices of box 2. If the following lines return an empty "result", then the boxes do not overlap. Otherwise, they do.
[A1,b1]=vert2lcon(V1);
[A2,b2]=vert2lcon(V2);
result=lcon2vert([A1;A2],[b1;b2]);
  7 Comments
Image Analyst
Image Analyst on 4 Nov 2012
How do you have the bounding box for the A? If you do, then you must have labeled it. But then there are other small regions inside the A, and those would also have labels and bounding boxes. And of course there is the large triangle in the A which would be its own region. Plus it looks like you may have breaks in the edges, so that the A may really be 2 or 3 or 4 regions, not just one, and would thus have bounding boxes that don't enclose the whole A. But let's just assume you didn't have any of those problems. Let's assume you had a nice A that had contiguous, non-broken outlines and you did an imfill on it so that you had a solid region with just one bounding box. Again, it's labeled so all you need to do is to extract that one label from the image using ismember(). That would get rid of any regions with a different label number that intruded into the bounding box of the A. So I'm glad you explained the situation because now we can see that what you thought you wanted to do is actually not necessary at all. You can do it easily and simply with ismember() and not have to worry at all with binary images or inspecting corner coordinates.
By the way, I don't really think finding edges to identify characters is the way to go. I think a background flattening followed by thresholding would be the way to go, but I'm not really familiar with OCR methods and if edge finding is a required step in some successful pubished method that you have seen, then maybe it's alright, though it seems fraught with additional problems that thresholding would not have (internal outlines, broken outlines, etc.).
Muffin
Muffin on 19 Dec 2012
There is no bounding box for A. Its just that the character is already segmented in the input data. You mentioned "Let's assume you had a nice A that had contiguous, non-broken outlines and you did an imfill on it so that you had a solid region with just one bounding box." I cannot do that assumption as I have to work with characters that have broken contour lines.
So i have to find a way to compare the bounding coordinates of the different connected components in the image then remove the non-overlapping regions. How do I do that?

Sign in to comment.


Stalin Sabu Thomas
Stalin Sabu Thomas on 20 Oct 2018
ratio = bboxOverlapRatio(bbox1, bbox2)
This can actually give you a matrix which shows how much overlap exists between a pair of bboxes. Take a look at their documentation https://in.mathworks.com/help/vision/ref/bboxoverlapratio.html
I wasn't able to understand your objective completely but I am sure this is the answer.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!