2
$\begingroup$

How can I detect a quadrilateral in a point cloud that looks almost like a rectangle? How do I set the criteria (i.e orientation, size etc) to get the shape for example in the image below?

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Is the rectangle allowed to be arbitrarily rotated or should it be axis-aligned? The latter case is much easier to solve using lookup tables. $\endgroup$ – Libor Dec 25 '13 at 16:58
  • $\begingroup$ It axis-aligned but the top and bottom sides don't have to be exactly horizontal all the time (e.g Side 1-2) $\endgroup$ – askingtoomuch Dec 26 '13 at 5:38
1
$\begingroup$

There is one possible solution which is roughly $O(n\cdot (n-1)\cdot log(n))$ where $n$ is the number of points.

  1. Build 2-dimensional k-d tree from all the points
  2. For each pair of unmarked (undiscovered) points

2.1 Determine two areas (based on rectangle criteria) where the other two points can possibly lay

2.2 Find nearest point to center of each of the areas (using the k-d tree)

2.3 If each nearest point is unmarked and lays within its respective area, store new rectangle, mark all four points as discovered

The algorithm can be optimized by keeping undiscovered points in a set, picking new ones from the, progressively reducing its size.

Another speedup would be removing discovered points from the KD-tree so the algorithm does not have to check them in step 2.3.

$\endgroup$
  • $\begingroup$ I understand how kd-tree works but I don't really get what you mean by "determining two areas based on rectangle criteria" in step 2.1. Do you mean the area where P1, P3 lie, and the area where P2, P4 lie? $\endgroup$ – askingtoomuch Dec 26 '13 at 5:34
  • $\begingroup$ and how do I filter other possible shapes like 1-2-4-5, 1-2-6-5 etc? $\endgroup$ – askingtoomuch Dec 26 '13 at 5:43
  • $\begingroup$ You may define a threshold by determining how likely it is to find such a rectangle (as defined by the algorithm) in a set of randomly positioned dots $\endgroup$ – meduz Dec 27 '13 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.