fitting rectangle through data points

Let's say I have the data as shown in OXY plane(Here, I show 2 examples):
How can I fit the rectangle through data:

 Respuesta aceptada

darova
darova el 26 de Mayo de 2019

2 votos

If your data always has V form (look like triangle). Tree corners can be found. Find farthest corners using pdist2()
img.png
Use wikipedia formula to find the 3rd corner of a triangle (wiki)
img1.png
Divide points into 2 groups. If distance point-corner smaller than radius:
img2.png
Use polyfit() to calculate coeffiecients of line. What if angle between calculated lines is not 90 degree?

3 comentarios

ha ha
ha ha el 31 de Mayo de 2019
Editada: ha ha el 31 de Mayo de 2019
Thanks @darova for good idea.
But I would like to consider for general case( section may have 2 sides, 3sides, or 4sides).
Because in general, I don't know my data contain 2, 3 (as my illustration photo) or full 4 sides of square(rectangle) shape. Do you have any idea for general case?
Image Analyst
Image Analyst el 31 de Mayo de 2019
Do a web search for "Minimum bounding perimeter MATLAB"
darova
darova el 31 de Mayo de 2019
Use pdist2() to find farthest corners. Draw a line from those points. Find another corners
img.png
Divide points into 4 sets using some tolerance distance to lines
img1.png
Apply polyfit() to each set
img2.png
It's the best i can

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 25 de Mayo de 2019

1 voto

What I would try first is to use principal components analysis ("PCA") to identify the two axes. Use pca() if you have the stats toolbox. Then you can fit lines with polyfit() going through the points along each PC. Use the points at the limits to determine where the lines start and stop. Sorry, no I don't have code that does this already - I'd have to develop it just as you would.
Another method you might also try is RANSAC.

1 comentario

ha ha
ha ha el 25 de Mayo de 2019
Editada: ha ha el 25 de Mayo de 2019
Thanks @Image Analyst for your kind.
Can you show example code of rectangle fitting using pca? I try to follow your advice but I am not totally understand.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 25 de Mayo de 2019

Comentada:

el 31 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by