I've got a binary raster like this:
101101
010111
101011
111101
Now I need to do this row by row: Go through row and count the adjacent cells which are 1 (only the cells in the row!). And I would like to get a vector or something like this. for example for the raster above it would be:
1st row: 1 2 1
2nd row: 1 3
3rd row: 1 1 2
4th row: 4 1
I read a lot about flood filling algorithm and so on. But I just don't get it right.
I tried this recursive algorithm:
rec=function(x)
{if (x==0)
{return 0)
else return(1+rec(x+1))}
But it's not working.
You could try using
rle
.