Reduce number of pixels in Flexcol with mask
The number of rectangles can be greatly reduced if we combine neighbors and replace replace them with a single rectangle. An algorithm doing this is described here: http://www.drdobbs.com/database/the-maximal-rectangle-problem/184410529
If applied as long as there are neighbors that share an edge one can reduce the number of rectangles and memory greatly.