I have a matrix for a black and white photo, so 1s and 0s.
I want to horizontally measure the length, in pixels, of each black region in the photo. So the number of 0s.
How can I count the number of consecutive 0's for each row? Bare in mind for each row it is likely there are more than one group of consecutive 0's. I want a count value for each group of consecutive 0s in each row.
For example: I have a matrix
X = [1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0; 1 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0]
So I want it to tell me:
Row 1: 2 groups of 0's, length of each: 5 and 4 respectively
Row 2: 3 groups of 0's, length of each: 3, 4, and 2 respectively
Any help would be greatly appreciated!
Best Answer