Distance between bounding corners

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:
im.jpg
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 :)
im2.jpg

Antworten (1)

Adam Danz
Adam Danz am 17 Dez. 2019
Bearbeitet: Adam Danz am 17 Dez. 2019

0 Stimmen

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
r_com3 am 17 Dez. 2019
BoundingBox from regionprops is not the best solution in my task because the rectangle is not "matching" the shape object. I mean its not orientated so its less accurate.
When im using BoundingBox from regionprops its easy to calculate corners, but using the function i mentioned before i dont know how to refer to its data. Do u know how to overcome this problem?
Thank you for mentioning pdist2 function, it will be useful in the next steps probably
Adam Danz
Adam Danz am 17 Dez. 2019
Bearbeitet: Adam Danz 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
r_com3 am 19 Dez. 2019
Hello, so i figured out how to get coordinates of the corners from this function and it looks like this:
bound.jpg
All i did was to set the corrdinates from the function code, to the output of the program, so it was not that hard.
But my next question is ,
Is there a method of finding the corners of the 5 objects (white shapes) on the image?
Corner detection using for example Harris corner detection is not working since many corners are "rounded" so they are not detectable.
Thanks for help in advance
Adam Danz
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
r_com3 am 21 Dez. 2019
I found a PixelList in regionprops.
If i get it right, in PixelList i have coordinates of each pixel belonging to object.
Is checking distance between each pixel and corner of bounding box a good idea?
Thanks for help
Image Analyst
Image Analyst am 21 Dez. 2019
Which bounding box do you mean? Like:
  1. one from regionprops(), or
  2. the tilted one you got somehow, or
  3. 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."
screenshot.jpg
Adam Danz
Adam Danz am 22 Dez. 2019
@r_com3, In which thread are you continuing this conversaion? This one or the other one?

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 17 Dez. 2019

Kommentiert:

am 22 Dez. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by