I have an image. The pixel value is either 0 or 1. All pixels are initially zero.
Given a set of overlapping rectangles characterized by (bottom left pixel coordinate, width, height), I need to flip every pixel inside a rectangle. The following figure shows a toy example:
I have tens of millions of such images to fill. Each image has tens of thousands of pixels. The overlapping rectangles associated to each image are quite many.
The naïve approach is to just iterate through the set of rectangles for every image. But in our case, because the number of rectangles and the overlapping areas are all huge, the computational wastes are substantial.
I intend to code an algorithm by first finding the union sets for each column, like the following:
But before committing to it, is there a well established algorithm for solving this problem? It seems quite fundamental in computer vision / image processing.
1