Distance between bounding corners
Ältere Kommentare anzeigen
Hello, i am struggling with task of finding the distance between corners of bounding boxes of objects.
My image with bounding box around the objetcs looks like this:

The oriented bounding box is taken from the algorythm in this link :
My task is to find the green and blue distances on the image.
Anyone has idea how to perform it ?
Thanks in advance :)

Antworten (1)
You could probably achieve the same results using regionprops from the Image Processing Toolbox (see BoundingBox property). In either case, you need to get the coordinates of the rectangle from the function output. Then you can use the pythagorean distance formula [video][literature] or Matlab's, pdist2() to compute the distance between the corners of each bounding box. It's probably easiest just to compute the distance between all 4 corners of box N and box N+1 and then the two closest corners are the ones you're interested in.
If you get stuck, show us how far you got and we can help out with the next steps.
7 Kommentare
r_com3
am 17 Dez. 2019
From the file exchange link you shared, I believe you're using the drawOrientedBox function (correctly me if I'm wrong).
varargout = drawOrientedBox(box, varargin)
That produces an output. I looked at the code and it looks like it's outputting the plot handles to the polygons. You can get the XData and YData from those line object handles. I have no idea how those data are organized. After you take a hack at it, if you get stuck maybe you could describe what kind of data you've got.
(I haven't tested it myself since I haven't downloaded the files).
r_com3
am 19 Dez. 2019
Adam Danz
am 19 Dez. 2019
Good work! But those corner coordinates could have been extracted from the current outputs to the function instead of adding new output (just FYI).
Just note that if you ever update that function with a new version, you'll need to make those changes again.
"Is there a method of finding the corners of the 5 objects (white shapes) on the image?"
As you metioned, those objects do not have defined corners. One thing you could try is to find the nearest point along the border to each of the red rectangle borders. To do that, you'd get the coordinates of the object edges and then use pdist2 (as in my answer) to compute the distance between each edge coordinate to each red corner coordinate.
r_com3
am 21 Dez. 2019
Image Analyst
am 21 Dez. 2019
Which bounding box do you mean? Like:
- one from regionprops(), or
- the tilted one you got somehow, or
- the corners of the entire image?
You might also be interested in simply Using John D'Errico's bounding rectangle app: A suite of minimal bounding objects. It's a "Suite of tools to compute minimal bounding circles, rectangles, triangles, spheres, incircles, etc."

Adam Danz
am 22 Dez. 2019
Kategorien
Mehr zu Region and Image Properties finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
