prtools.centroid#
- centroid(x, where=None, mode='absolute', indexing='ij')[source]#
Compute array centroid location.
- Parameters:
x (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.
mode ({'absolute', 'center'}, optional) – Specifies how the centroid is computed. 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.0, 178.0) >>> prtools.centroid(circ, mode='center') (-80.0, 50.0) >>> prtools.centroid(circ, mode='center', indexing='xy') (50.0, -80.0)