Algorithm to reduce a bitmap mask to a list of rectangles?
Posted
by
mos
on Game Development
See other posts from Game Development
or by mos
Published on 2012-06-23T18:06:07Z
Indexed on
2012/06/23
21:25 UTC
Read the original article
Hit count: 393
Before I go spend an afternoon writing this myself, I thought I'd ask if there was an implementation already available --even just as a reference. The first image is an example of a bitmap mask that I would like to turn into a list of rectangles. A bad algorithm would return every set pixel as a 1x1 rectangle. A good algorithm would look like the second image, where it returns the coordinates of the orange and red rectangles. The fact that the rectangles overlap don't matter, just that there are only two returned.
To summarize, the ideal result would be these two rectangles (x, y, w, h): [ { 3, 1, 2, 6 }, { 1, 3, 6, 2 } ]
© Game Development or respective owner