prtools.centroid#
- centroid(a, where=None, kind='absolute', indexing='ij')[source]#
Compute array centroid location.
- Parameters:
a (array_like) – Input array.
where (array_like of bool, optional) – Elements to include in the centroid calculation. If None (default), all finite and non-NaN values are used.
kind ({'absolute', 'center'}, optional) – Specifies the kind of centroid as a string. If ‘absolute’ (default), the absolute centroid within the input is returned. If ‘center’, the centroid relative to the center of the input is returned.
indexing ({'ij', 'xy'}, optional) – Matrix (‘ij’, default) or cartesian (‘xy’) indexing of mesh.
- Returns:
centroid – (r, c) or (x, y) centroid location
- Return type:
tuple
Examples
>>> circ = prtools.circle(shape=(256, 256), radius=25, shift=(-80, 50)) >>> plt.imshow(circ, cmap='gray')
>>> prtools.centroid(circ) (48.00000000000002, 178.0) >>> prtools.centroid(circ, kind='center') (-79.99999999999997, 50.0) >>> prtools.centroid(circ, kind='center', indexing='xy') (50.0, 79.99999999999997)