I have a set of 5x5 Boolean matrices, one of which is below:
0 1 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1
And I would like to get an output method for each connected series of 1 (the connected meaning of a 1 is on the left, on the right, above or below another 1, the diagonals are not taken into account). The length it occupies on the x axis and the length it occupies on the y axis. EG. for this matrix. There will be one that goes completely from left to right, so 5 units in x and 4 units in y:
1 1 1 1 1 1 1 1 1 1 1
In the upper right corner there will also be a set that has 2 units in x and only 1 in y:
1 1
and in the lower right corner there will be one that takes only 1 in x and 1 in y.
I would like for this matrix to output something along the line xmax1 = 5 ymax1 = 4, xmax2 = 2 ymax2 = 1, xmax3 = 1 ymax3 = 1. I managed to make a code that goes along the correct line, but only works for simple matrices. For instance. one where there is only one connected set of 1s, and where xmax and ymax are just simple straight lines, for example. I can do this for:
1 1 1 1 0 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0
Since the longest path x is a straight line from above, and the longest y max is a straight line down. However, if he begins to "snake", for example:
0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 1 1
I would choose the result ymax = 3 and xmax = 3, since they are the longest straight lines, and not what they really should be, this is the length from the most distant from each other, so in this case there should be ymax = 5 and xmax = 4
I am new to MatLab and trying to teach myself, and so I think I can come up with a lot of methods that will work, however I can not figure out how to implement them. I tried several methods, but I can not imagine how to implement them correctly.
Thanks for any help.