Skip to content

Instantly share code, notes, and snippets.

@dridk
Created August 10, 2021 17:40
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 dridk/e62e157250bd5419273dfaac9db64be6 to your computer and use it in GitHub Desktop.
Save dridk/e62e157250bd5419273dfaac9db64be6 to your computer and use it in GitHub Desktop.
image_coord_motif_detection
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage.io 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()
plt.imshow(img)
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