Filling Polygons in a 2D Matrix

4 views (last 30 days)
Andrew Colhoun
Andrew Colhoun on 24 Feb 2014
Hello,
I am having a problem filling arbitrary “polygons” within a 2D matrix with a particular value. Any help would be greatly appreciated.
Basically, I have large 2D matrix filled with 0’s and 1’s. The 1’s form the edges of polygons within the matrix. Given a particular index/point within the matrix, I want to fill the area around it (bounded by 1’s) with a particular value.
E.g.
Matrix =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
If I select a point within the matrix (will be a 0), for this example (4,11) and select a flood value of 8. I want the output to be
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 1 8 8 8 8 8 8 1 1 1 1 1 1
0 0 0 0 0 0 0 1 8 8 8 8 8 1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 8 8 8 8 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Thanks in advance,
Andrew

Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!