Hello.
Does anyone know of any code that finds continuous regions? To be more
exact:
I have a 3D dataset, say 64x64x64. Within this array, many entries
will be 1, some will be zero. Is there an easy way to identify all the
groups of array elements equal to 1 which lie adjacent to each other?
For a 1D dataset this is what I'm looking for:
arr=[0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1,1,1,1,1, 0, 0, 0, 0]
first second third
So, there are three continuous regions. (I don't care about isolated
1's).
I'd like to have an array (arr2) returned where I'd have something
like:
arr =[0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1,1,1,1,1, 0, 0, 0, 0]
arr2=[0, 1, 1, 0, 0, 0, 2, 2, 2, 0, 0, 0, 3,3, 3,3,3, 0, 0, 0, 0]
As I said, I need such a thing for a 3D array....
I expect I'm looking at recursive routines which I've always had
trouble getting my mind around. I'd rather not re-invent the wheel if
I can avoid it.
Thanks!
Mark
|