Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need idea for algorithm - fill holes in matrix

Started by prezaKG Feb 21, 2012 at 5:06 PM 1 replies 2.2k views
Original Post
prezaKG
prezaKG
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):
daau.jpg

I need matrix to look like this:
dywqdz.jpg


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.
Waterlimon
Waterlimon
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...
o3o
prezaKG
prezaKG

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...


Great! That was fast.
Thx!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.