A Merging Heuristic for the Rectangle Decomposition of Binary Matrices

In this paper we present a linear-time and linear-space algorithm for the decomposition of binary images into rectangles. Our contribution is a two-stage algorithm. In the first stage we compute a $${\textstyle \frac{1}{minh,w}}$$1minh,w-approximation for the largest rectangle starting at each point of the matrix. In the second stage the algorithm walks through the matrix, alternatively stacking, merging or removing encountered rectangles. Through an experimental evaluation, we show that our algorithm outperforms state-of-the-art linear-time algorithms for small to medium-sized rectilinear polygons.