This is documentation for an old release of SciPy (version 0.9.0). Read this page in the documentation of the latest stable release (version 1.15.1).
Calculate the center of mass of the values of an array at labels.
Parameters : | input : ndarray
labels : ndarray or None, optional
index : int, sequence of int, or None, optional
|
---|---|
Returns : | centerofmass : tuple, or list of tuples
|
Examples
>>> a = np.array(([0,0,0,0],
[0,1,1,0],
[0,1,1,0],
[0,1,1,0]))
>>> from scipy import ndimage
>>> ndimage.measurements.center_of_mass(a)
(2.0, 1.5)
Calculation of multiple objects in an image
>>> b = np.array(([0,1,1,0],
[0,1,0,0],
[0,0,0,0],
[0,0,1,1],
[0,0,1,1]))
>>> lbl = ndimage.label(b)[0]
>>> ndimage.measurements.center_of_mass(b, lbl, [1,2])
[(0.33333333333333331, 1.3333333333333333), (3.5, 2.5)]