您可以使用此处提到的解决方案之一将图像读入 numpy 数组:Importing PNG files into Numpy?
然后你可以使用numpy.argwhere函数numpy.argwhere(image_array > treshold)返回灰度值大于某个阈值的索引
import matplotlib.pyplot as plt
import numpy as np
im = plt.imread('3zu5i.png')
#https://*.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.2989, 0.5870, 0.1140])
grey = rgb2gray(im)
coordinates = np.argwhere(grey < 0.99)
这应该返回一个数组,其中包含灰度值大于某个阈值的数组索引
array([[ 41, 280],
[ 41, 281],
[ 41, 282],
...,
[372, 299],
[372, 300],
[372, 301]])