I have a binary image containing a single contiguous blob, with no holes. I would like create a polygon object based on the exterior edges of the edge pixels. I know how to get the edge pixels themselves, but I want the actual coordinates of the pixel boundaries, sorted clockwise or counter-clockwise. All of the pixels have integer coordinates.
For example, say I have a single pixel at (2,2). The vertices of the polygon would be: (2.5, 2.5) (2.5, 1.5) (1.5, 1.5) (1.5, 2.5) (2.5, 2.5)
Is there an exact, non-approximate way to do this? Preferably in Python?
Based on the comments, here is the approach that I implemented:
multiply all pixel coordinates by 10, so that we'll only deal with integers.
For each pixel, generate the 4 corners by adding +/- 5. For example, for (20,20), the corners are (25, 25) (25, 15) (15, 15) (15, 25) (25, 25). And store all the corners in a list.
Count the occurrences of each corner. If the count is odd, it is a corner to the blob. Making the coordinates integers makes this step easy. Counting floats has issues.
Divide the blob corner coordinates by 10, getting back the original resolution.
Sort the corners clockwise using a standard algorithm.