BW = poly2mask(x, y, m, n)
computes a binary region of interest (ROI) mask, BW, from an ROI polygon, represented by the vectors x and y. The size of BW is m-by-n.
poly2mask
sets pixels in BW that are inside the polygon (X,Y) to 1 and sets pixels outside the polygon to 0.
Problem:
Given such a binary mask BW
of a convex quadrilateral, what would be the most efficient way to determine the four corners?
E.g.,
Best Solution so far:
Use edge
to find the bounding lines, the Hough transform to find the 4 lines in the edge image and then find the intersection points of those 4 lines or use a corner detector on the edge image. Seems complicated, and I can't help feeling there's a simpler solution out there.
Btw, convhull
doesn't always return 4 points (maybe someone can suggest qhull
options to prevent that) : it returns a few points along the edges as well.
EDIT:
Amro's answer seems quite elegant and efficient. But there could be multiple "corners" at each real corner since the peaks aren't unique. I could cluster them based on θ and average the "corners" around a real corner but the main problem is the use of order(1:10)
.
Is 10
enough to account for all the corners or will this exclude a "corner" at a real corner?