Sign in to follow this  
prezaKG

Need idea for algorithm - fill holes in matrix

Recommended Posts

prezaKG    135
Need idea for algorithm - fill holes in matrix

I need idea to write a algorithm that will fill "holes" in my matrix.
Matrix looks like on this picture (white squares have FALSE values and black squares have TRUE values):
[img]http://i40.tinypic.com/daau.jpg[/img]

I need matrix to look like this:
[img]http://i41.tinypic.com/dywqdz.jpg[/img]


Any idea how to find this holes in matrix and fill them with black squares (i.e. assign TRUE values to those matrix members)?

p.s. My matrix is quite large and I have a lot of matrices to examine.

Share this post


Link to post
Share on other sites
Waterlimon    4398
You would pick a random white cell that is considered "outside" the black area, then you flood to the surrounding tiles until you have no more white cells to flood. Then you find all the white cells that didnt get flooded and turn them black.

If you [s]want[/s] need ugly optimizations, you could make the pic in a quadtree with all bottom level nodes existing, and have the not-top-level nodes be either black white or both, so you can flood at a higher level if the high nodes are only of single color, and then go deeper in the tree to flood smaller areas when you get to an node with both black and white.

Something like that.

Edit: Though im not sure if that would be even faster...

Share this post


Link to post
Share on other sites
prezaKG    135
[quote name='Waterlimon' timestamp='1329844337' post='4915209']
You would pick a random white cell that is considered "outside" the black area, then you flood to the surrounding tiles until you have no more white cells to flood. Then you find all the white cells that didnt get flooded and turn them black.

If you [s]want[/s] need ugly optimizations, you could make the pic in a quadtree with all bottom level nodes existing, and have the not-top-level nodes be either black white or both, so you can flood at a higher level if the high nodes are only of single color, and then go deeper in the tree to flood smaller areas when you get to an node with both black and white.

Something like that.

Edit: Though im not sure if that would be even faster...
[/quote]

Great! That was fast.
Thx!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this