Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2021 17:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from import imread
from skimage.color import rgb2gray
from skimage.filters import threshold_otsu
from skimage.measure import label
img = imread("A.png")
img = rgb2gray(img)
thresh = threshold_yen(img)
binary = img >= thresh
img = label(binary, return_num=False)
grp = img.max()
for i in range(1, grp+1):
points = np.argwhere(img == i)
center = points.sum(axis=0) / len(points)
plt.plot(center[1], center[0], "ro")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment