Skip to content

Instantly share code, notes, and snippets.

@LeeKamentsky
Created March 21, 2018 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeKamentsky/a7a477296f69e37e19a3667b0e474765 to your computer and use it in GitHub Desktop.
Save LeeKamentsky/a7a477296f69e37e19a3667b0e474765 to your computer and use it in GitHub Desktop.
Function to get centers of labels
def centers(l):
z, y, x = np.where(l > 0)
a = np.bincount(l[z, y, x])
xx = np.bincount(l[z, y, x], x)
yy = np.bincount(l[z, y, x], y)
zz = np.bincount(l[z, y, x], z)
return np.column_stack(
(zz.astype(float) / a, yy.astype(float) / a, xx.astype(float) / a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment