Reputation: 118
I have an image with size of M*N. Each pixel can be selected or not selected.
Given selection values for each pixel (selected or not), what is the most efficient algorithm to get the set of polygons which represents a selection?
Upvotes: 0
Views: 89
Reputation: 36401
I think any filling algorithm can be suitable:
Upvotes: 1
Reputation: 10151
Diagonals might be tricky, because of pixel-exact rounding errors, so I would go only for rectangles with horizontal and vertical lines (overlapping ones can be merges to a polygon)
I would perform the following steps:
connect selected neighbours of selected pixels to horizontal lines
connect horizontal lines to rectangles
connect overlapping/touching rectangles to a polygon
Upvotes: 1