How to fit polygon to irregular set of points with only vertical and horizontal edges?

9 次查看(过去 30 天)
Hi everyone,
I've been battling with this for a few days now, so hoping for some help on here. I have a set of points (actually quite a few sets, over 11k) that form a boundary around an area of interest. I'm trying to calculate the average value of pixels within each boundary. My issue is that the set of points is not ordered cw or ccw - it's basically random. They are also not concave, and so I can't use (or I can't figure out) the polygon functions (polyshape, boundary, alphaShape, convhull, etc) as they do not draw the boundaries correctly, and hence can't use inpolygon or poly2mask functions.
At the moment, the best I can get is by calculating the angle of each point from the centroid and then putting them in order following THIS answer, however this does not work for certain parts of the areas of interest - see the figures below. The markers represent the set of points, and the blue/orange is the best polygon I've been able to draw so far for each. The top right corner shows in a red line what the boundary should be.
Any ideas or suggestions for me to look at?
Thanks in advance!

采纳的回答

Matt J
Matt J 2024-6-3
编辑:Matt J 2024-6-3
You will need to use a Traveling Salesman Problem solver to sort the vertices. There are a number of them on the File Exchange. This one has worked well for me,

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by