Jump to content



Need idea for algorithm - fill holes in matrix

  • You cannot reply to this topic
2 replies to this topic

#1 prezaKG   Members   -  Reputation: 134

Like
0Likes
Like

Posted 21 February 2012 - 11:06 AM

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):
Posted Image

I need matrix to look like this:
Posted Image


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.

Ad:

#2 Waterlimon   Members   -  Reputation: 162

Like
1Likes
Like

Posted 21 February 2012 - 11:12 AM

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 want 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...
My face when i saw i have almost 1000 profile views. I feel popular among random web browsing bots.

#3 prezaKG   Members   -  Reputation: 134

Like
0Likes
Like

Posted 21 February 2012 - 11:22 AM

View PostWaterlimon, on 21 February 2012 - 11:12 AM, said:

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 want 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!






We are working on generating results for this topic
PARTNERS