Given an image with a fixed palette (e.g. 256 colors)
Create an algorithm to divide that image into rectangular regions, each of which consists of the pixels of the same color. Regions can overlap, the order of them also matters (the last region will be drawn on top of others). The number of regions should be as small as possible.
Alternative formulation of the problem: draw an image using the smallest number of fill
instructions.
I'm pretty sure that this problem is NP-complete, so a faster solution would be better than an exact one taking forever to run.
The simplest approach would be scanning the image line-by-line and producing rectangles with height of 1. But that is not very effective.
I were also thinking about creating a quadtree and then merging adjacent regions (merging would require some sort of heuristics to choose the best pair to merge).
The two above algorithms don't consider that the regions may overlap. We can draw a huge region, then drawing details above it.
Any ideas?