Need idea for algorithm - fill holes in matrix

Started by
1 comment, last by prezaKG 12 years, 1 month ago
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.
Advertisement
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


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!

This topic is closed to new replies.

Advertisement