I am working with a series of numpy.ndarray
made of 101x101 values ranging 0.0 to 1.0. All arrays look like this:
array([[ 0.216, 0.24 , 0.244, ..., 0.679, 0.684, 0.707],
[ 0.23 , 0.229, 0.238, ..., 0.675, 0.676, 0.695],
[ 0.221, 0.238, 0.24 , ..., 0.669, 0.677, 0.684],
...,
[ 0.937, 0.925, 0.923, ..., 0.768, 0.754, 0.752],
[ 0.937, 0.929, 0.923, ..., 0.737, 0.735, 0.741],
[ 0.934, 0.932, 0.929, ..., 0.72 , 0.717, 0.728]])
Now, say that I have a threshold value=0.2
: how could I locate the "regions" of values within the matrix in such a way that, within them, the threshold is exceeded? In this case, I would be looking for regions which values are >=0.2
.
In particular, I would like to:
- Count the number of regions that exceed the
threshold value
; - Determine their
centers of mass
.
I know that I can compute the latter by means of: ndimage.measurements.center_of_mass()
, but I fail to see how it could be applied to just "regions" of a matrix rather than the whole thing.
EDIT
Please consider that the "regions" I refer to have irregular shapes.