Reputation: 3888
Suppose you're given a vector<vector<bool>>
(square region) where a 1 corresponds to a "filled" box. Are there any methods to find whole regions in O(n) time? For example, this vector will have two whole regions:
0 0 1 1 1 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0
0 1 0 0 1 0 0 0
0 0 1 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0
Upvotes: 1
Views: 105
Reputation: 12152
This is called 8-connected region growing. It is a standard technique in image processing, you select a seed pixel and "grow". This can be done with BFS in linear time in the number of pixels:
The region list contains a region, set that to zero. Find another seed and run again, until you can't find seeds.
Upvotes: 3