Computational Science Asked by jwd on February 15, 2021
I have a 2D SDF describing my shape, but it’s fine to think of it as a black/white image (black="inside" white="outside").
I want to generate a small set of rectangles (say, 8 of them) covering the image, which are allowed to overlap, and which minimize the amount of error. Error would be any leftover "black" areas of the image that are not covered.
The image could be convex, have holes, etc. It is general.
I realize that minimal rectangle covering is NP-hard, though that’s not exactly what I’m asking for: I’m asking for minimizing error given a finite set of rectangles to work with. Maybe it’s just as hard though; not sure.
Anyway, I do not need to find the perfect solution; decent heuristics would be fine.
I could imagine some pretty general "greedy search" traversal of the state space, but wondered if there were any tricks anyone knows of.
Aside: I’ve also looked at several papers for "rectangular decomposition", and "minimal dissection", but those problems generally assume I want disjoint rectangles. Disjoint would be okay, but really I want maximal coverage while allowing overlap.
Edit Here is an example:
Target image:
Covering with 4 rectangles (red, green, blue, yellow):
Any uncovered black pixels are the "error".
No white pixels are allowed to get covered.
(I do not claim any optimality, or that I have thought of every detail)
1. Downsample and brute force: You project your black and white map onto a low resolution. On this lower resolution, you may represent any rectangle by two points marking the upper left and lower right corner. If your resolution is low enough, you can iterate through all non-redundant combinations of points, test if they overlap with white areas (i.e. at the enclosed islands), and if not, then you may efficently calculate their area. As you have four rectangles the skaling of the problem will be very bad, but for low resolution you might get away with it.
2. Heuristic: 'growing' rectangles: You pick four locations that lie within the black area. For each of these locations, you 'grow' rectangles outwards until they touch any white area. If you only hit white in x- or y- direction you may still grow into the other one.
You repeat the above process for a large number of seeding points (preferrably in parallel), and then pick the winner. You might also do variations in that you only pick the first point, optimize the corresponding maximally grown rectangle, and then move to the second one etc.
3. Projection : You go to a high resolution grid, and integrate for every row and column, how many black and white pixels there are. In the vertical profile you get for the integration along your rows, and the horizontal profile you get from integrating your columns you can easily determine the maxima, which would be a good place for starting to place (or grow) a rectangle. Then, when you place the second one, you do the same process but take into account the area that you already covered with the first one. You will have to do some corrections for corner cases, but it might save you a lot (numerical) work. I apologize in advance for the following sketch of what i mean:
As I said, this does not really solve your problem, but might be starting points for constructing a heuristic.
Answered by MPIchael on February 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP