1

I am working on image segmentation and I thought the convex hull can provide me with a simple solution to my problem. Currently I have polygons with for sides (see image below). Due to image processing issues, the shape does not have clean straight sides and hence when I use the standard convex hull (in Matlab) I may get more than the four main corners to define it.

My goal is to force the convex hull algorithm to find the best 4 vertices that will enclose my polygons (i.e. 4 best enclosing vertices per polygon). Is this possible? An example code will be appreciated.

Thanks

enter image description here

user84310
  • 121
  • 1
  • 6
  • There's a suite of functions available on the [mathworks file exchange](https://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of-minimal-bounding-objects) which provides implementations of minimum area and minimum perimeter bounding quadrilateral algorithms. – jodag Jan 21 '18 at 06:25

1 Answers1

1

The problem of the minimum area bounding polygon is briefly mentioned in "Geometric applications of a matrix-searching algorithm" (see Applications section). It is not simple and is probably not the way for you.

For an easier (but approximate) answer to your question, you can consider the four cardinal directions and find the farthest points in these, which define a quadrilateral. (Also consider the four intermediate directions, which are more appropriate for an axis-aligned rectangle.)

enter image description here

If you insist having an enclosing quadrilateral, you can translate the four edges to the farthest points in the respective perpendicular directions, and find the pairwise intersections.

If you insist having a rectangle, compute the convex hull and find the minimum area or minimum perimeter bounding rectangle by the Rotating Calipers method. https://geidav.wordpress.com/tag/rotating-calipers/

  • To the editor: was meaning polygon (of k sides). Thanks for the notice. –  Jan 21 '18 at 17:20
  • Yes, this will give an approximate solution, but the quad is not guaranteed to enclose all points. It really depends if this is fine for the asker's application. Because the main issue seems to be imprecisely segmented points this sounds that it won't be a problem. Also a good way to get the rectangle axes is with PCA. – Toby Collins Jan 21 '18 at 18:06
  • @TobyCollins: I have added material to address the enclosing issue. –  Jan 21 '18 at 18:25
  • yes I see. it might also be worth adapting if the goal is to have a rectangular quad, but this wan't clear from the question. – Toby Collins Jan 21 '18 at 18:40