Created
March 21, 2018 15:42
-
-
Save LeeKamentsky/a7a477296f69e37e19a3667b0e474765 to your computer and use it in GitHub Desktop.
Function to get centers of labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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