Bounding box on clusters in a 2D list
Bengt Richter
bokr at oz.net
Sat Apr 23 23:44:36 EDT 2005
On 23 Apr 2005 13:17:55 -0700, "superprad at gmail.com" <superprad at gmail.com> wrote:
>If I have
>
>ex: x = [[1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],
> [1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0],
> [1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,0,0,0],
> [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0]]
>what I want is a boundingbox over the region where we find clusters of
>1's.So for instance in the above list first 3 roes and colums have 1's
>so the area of that box is 3x3
>so my final array should have an array of approx areas of clusters of
>1's like
>area = [ 9,4 ....]
Where does the 4 come from?
>Hope I am clear with my question.
>
Not quite clear on if "clusters" have to be rectangular and fill their bounding boxes
or whether
[[0, 0, 0, 0, 0],
+-----+
[0,|1, 1,|0, 0],
| |
[0,|0, 1,|0, 0],
+-----+
[0, 0, 0, 0, 0]]
is a cluster with three 1's. Or indeed whether "bounding boxes" have to be rectangular.
I.e., what about diagonal clusters?
,__,
[[0, 0,|1,|0, 0],
_/ _/ ,__,
[0,/1,/0, 0,|1],
_/ _/ _/ /
[1,/0, 0,/1,/0],
_/ /
[0, 0,/1,/0, 0]]
Or should that be
+-------------+
[[|0, 0, 1, 0, 0|],
| |
[|0, 1, 0, 0, 1|],
| |
[|1, 0, 0, 1, 0|],
| |
[|0, 0, 1, 0, 0|]]
+-------------+
since two 3x3 squares around the length-3 diagonals would overlap.
Regards,
Bengt Richter
More information about the Python-list
mailing list