Algorithm to split an image into smaller images reducing the amount of whitespace and specifying maximum amount of rectangles

后端 未结 5 1000
悲哀的现实
悲哀的现实 2021-01-03 01:08

I am looking for an algorithm which can split an image into smaller images, with some constraints. One constraint is to use the least amount of \"whitespace\" meaning empty

5条回答
  •  旧时难觅i
    2021-01-03 01:43

    Sorry for the late comment but it took me some time to find a "good" algorithm.

    After some research i am going for the following solution. First i use a Quadtree and do a SplitAndMerge. i Split on "Whitespace" first. Then i am merging all the rectangles together into the largest area rectangles.

    After that i sort the quadtree on area size, only keeping the largest x area's. (So essentialy keeping the largest whitespace areas). But i don't want the whitespace, i want everything except the whitespace so i invert the Quadtree, and do a SplitAndMerge Again. Then extracting the remaining rectangles out of the image, and binpacking them in the final image.

    This has given me some excellent results, reducing the image size drastically (because my images had a lot of whitespace in it), and keeping the time to draw them to a minimum.

提交回复
热议问题